Comments (1)
back to integrating this, and i managed to figure it out :) for anyone else, here's my example
class BankidController < ApplicationController
def index
auth = BANKID_CLIENT.generate_authentication(ip: request.remote_ip) # user's ip address
@qr_code = BANKID_CLIENT.generate_qr(
start_token: auth.qr_start_token,
start_secret: auth.qr_start_secret,
seconds: 0
)
@qr_start_token = auth.qr_start_token
@qr_start_secret = auth.qr_start_secret
@order_ref = auth.order_ref
@auth_timestamp = DateTime.now.to_i
end
def collect
# seconds elapsed from `auth_timestamp` (in seconds) to now
seconds = DateTime.now.to_i - params[:auth_timestamp].to_i
@qr_code = BANKID_CLIENT.generate_qr(
start_token: params[:qr_start_token],
start_secret: params[:qr_start_secret],
seconds: seconds
)
@qr_start_token = params[:qr_start_token]
@qr_start_secret = params[:qr_start_secret]
@order_ref = params[:order_ref]
response = BANKID_CLIENT.poll(order_ref: params[:order_ref])
raise 'logged in!' if response.status == 'complete' # testing
end
end
view that displays the qr code:
<turbo-frame id="qr_code" src="<%= collect_bankid_index_path(qr_start_token: @qr_start_token, qr_start_secret: @qr_start_secret, order_ref: @order_ref) %>" data-controller="poll" data-poll-interval="5000">
<%= render partial: 'qr_code', locals: { qr_code: @qr_code, qr_start_token: @qr_start_token, qr_start_secret: @qr_start_secret, order_ref: @order_ref } %>
</turbo-frame>
the partial:
<div class="text-center">
<div class="bg-white rounded p-4 inline-block border border-gray-200">
<%= local_assigns[:qr_code].as_svg(
module_size: 3,
shape_rendering: 'optimizeSpeed',
color: '00796b'
).html_safe %>
</div>
</div>
stimulus poll controller:
import { Controller } from '@hotwired/stimulus'
export default class extends Controller {
connect() {
if (!this.element.dataset.pollInterval) {
console.error('No poll interval set for element', this.element)
return
}
window.poll_interval = setInterval(
() => {
this.element.reload()
},
this.element.dataset.pollInterval,
this,
)
}
disconnect() {
clearInterval(window.poll_interval)
}
}
from bankid.
Related Issues (3)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from bankid.