(NOTE: This is based on these gems: omniauth-auth0
gem: https://github.com/auth0/omniauth-auth0.git and omniauth-azure-oauth2
gem)
Authenticate with Kinde Oauth2 using OmniAuth.
Add this line to your application's Gemfile:
gem 'omniauth-kinde-oauth2'
First, you will need to add your site details to the Application in Kinde Admin:
Then add the :kinde_oauth2
provider to your application configuration:
use OmniAuth::Builder do
provider :kinde_oauth2, ENV['KINDE_CLIENT_ID'], ENV['KINDE_CLIENT_SECRET'], ENV['KINDE_DOMAIN']
end
To configure params and things, just specify overrides as normal for OmniAuth provider:
(see options defined by the omniauth-oauth2
gem: https://github.com/omniauth/omniauth-oauth2/blob/master/lib/omniauth/strategies/oauth2.rb)
use OmniAuth::Builder do
provider :kinde_oauth2, ENV['KINDE_CLIENT_ID'], ENV['KINDE_CLIENT_SECRET'], ENV['KINDE_DOMAIN'],
authorize_params: {
scope: 'openid email profile offline'
}
end
Or the alternative format for use with devise:
config.omniauth :kinde_oauth2, ENV['KINDE_CLIENT_ID'], ENV['KINDE_CLIENT_SECRET'], ENV['KINDE_DOMAIN']
This is the structure of data returned from the Kinde /userinfo
endpoint
{
id => "kp_012345abcdef012345abcdef012345ab",
first_name => "Firstname",
last_name => "Lastname",
preferred_email => "[email protected]",
picture => null,
provided_id => null,
username => "MyUsername",
}
To run the example Sinatra app:
- Navigate to the examples directory:
cd examples
- Copy the
.env.example
file to.env
and fill in the variables - Start the server:
bundle exec rackup
- In your browser, navigate to the server (defaults to: http://localhost:4567)
Run tests bundle exec rake
Push to rubygems bundle exec rake release
.