Omniauth::SSL
- Add gem to Gemfile and bundle
gem "omniauth-ssl"
- Add the following ENV variables
OMNIAUTH_SSL_CLIENT_ID = ""
OMNIAUTH_SSL_CLIENT_SECRET = ""
OMNIAUTH_SSL_CLIENT_SCOPE = ""
OMNIAUTH_SSL_SITE = "http://127.0.0.1:3001"
OMNIAUTH_SSL_AUTHORIZE_URL = "http://127.0.0.1:3001/oauth2/authorize"
OMNIAUTH_SSL_TOKEN_URL = "http://127.0.0.1:3001/oauth2/token"
- Add configuration to
config/initializers/omniauth.rb
Rails.application.config.middleware.use OmniAuth::Builder do
provider :ssl,
ENV["OMNIAUTH_SSL_CLIENT_ID"],
ENV["OMNIAUTH_SSL_CLIENT_SECRET"],
scope: ENV["OMNIAUTH_SSL_CLIENT_SCOPE"],
client_options: {
site: ENV["OMNIAUTH_SSL_SITE"],
authorize_url: ENV["OMNIAUTH_SSL_AUTHORIZE_URL"]
token_url: ENV["OMNIAUTH_SSL_TOKEN_URL"]
}
end
- Add routes to your user sessions callback controller (will be unique depending on how your app is configured. you will need to change the to: paramaeters to match your app)
match "/auth/:provider/callback", to: "sessions#create", via:[:post, :get]
- Redirect User to oauth server
= link_to "log in with SSL", "/auth/ssl", method: :post
- Access the OmniAuth return and process login (You will need to create your custom logic here in rails to handle the token etc)
request.env['omniauth.auth']
request.env['omniauth.auth'].credentials.access_token
request.env['omniauth.auth'].credentials.refresh_token
request.env['omniauth.auth'].info