DigiID
This is the ruby implementation of the DigiID authentication protocol.
Installation
Add this line to your application's Gemfile:
gem 'digiid-ruby'
And then execute:
$ bundle
Or install it yourself as:
$ gem install digiid-ruby
Usage
Challenge
To build a challenge, you need to initialize a Digiid object with a nonce and a callback.
digiid = Digiid.new(nonce: @nonce, callback: @callback)
nonce is an random string associated with the user's session id.
callback is the url without the scheme where the wallet will post the challenge's signature.
One example of callback could be www.site.com/callback. A callback cannot have parameters. By default the POST call will be done using https. If you need to tell the wallet to POST on http then you need to add unsecure:true.
digiid = Digiid.new(nonce: @nonce, callback: @callback, unsecure: true)
Once the Digiid object is initialized, you have access to the following methods:
digiid.uri
This is the uri which will trigger the wallet when clicked (or scanned as QRcode). For instance:
digiid://digiid-demo.herokuapp.com/callback?x=000a00000b000cc0
If you added unsecure:true when initializing the object uri will then be:
digiid://digiid-demo.herokuapp.com/callback?x=000a00000b000cc0&u=1
To get the uri as a QRcode:
digiid.qrcode
This is actually a URL pointing to the QRcode image.
Verification
When getting the callback from the wallet, you must initialize a Digiid object with the received parameters address, uri, signature as well as the expected callback:
digiid = Digiid.new(address: @address, uri: @uri, signature: @signature, callback: @callback)
After you can call the following methods:
digiid.nonce
Return the nonce, which would get you the user's session.
digiid.uri_valid?
Returns true if the submitted URI is valid and corresponds to the correct callback url.
digiid.signature_valid?
If returns true, then you can authenticate the user's session with address (public DigiByte address used to sign the challenge).
Author
Vertbase Development Team
Contributing
- Fork it
- Create your feature branch (
git checkout -b my-new-feature) - Commit your changes (
git commit -am 'Add some feature') - Push to the branch (
git push origin my-new-feature) - Create new Pull Request