JSON Web Token (JWT) is a simple way to send verified information between two parties online. This can be useful as a mechanism for providing Single Sign-On (SSO) to an application by allowing an authentication server to send a validated claim and log the user in. This is how Zendesk does SSO, for example.
OmniAuth::JWT provides a clean, simple wrapper on top of JWT so that you can easily implement this kind of SSO either between your own applications or allow third parties to delegate authentication.
Add this line to your application's Gemfile:
gem 'omniauth-jwt'
And then execute:
$ bundle
Or install it yourself as:
$ gem install omniauth-jwt
You use OmniAuth::JWT just like you do any other OmniAuth strategy:
use OmniAuth::Builder do
provider :jwt, redirect_uri: "http://127.0.0.1:9292/auth/jwt/callback"
endREQUIRED parameters:
- token this is the encoded token retrieved by signing in a user on idplus that will be used by the external authenticator to verify that a user exists on idplus by using the getUserInfoCall.
- env: this is the idplus environment for the [getUserInfoCall]. Can either be
rc,devorprod
When you authenticate through omniauth-jwt you can send users to /auth/jwt?token=ENCODEDJWTGOESHERE&env=rc.
You can use the example sinatra app in example folder to test the
authentication:
cdinto theexamplefolder- run
bundleto install gems - start the application
shotgun --server=thin --port=9292 config.ru
You can now visit http://127.0.0.1:9292/auth/jwt?token=ENCODEDJWTGOESHERE&env=rc
PLEASE NOTE:
To retrieve the encoded token you can authenticate
via omniauth idplus strategy
and use the credentials["token"] value of the json response. Be sure to pass
as env parameter the SAME environment used to retrieve the token in the
omniauth idplus strategy.
"credentials": {
"token": "encoded_token",
"refresh_token": "refresh_token",
"expires_at": 1548777273,
"expires": true
}
- 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
