Class: Sorcery::Providers::Auth0
- Includes:
- Sorcery::Protocols::Oauth2
- Defined in:
- lib/sorcery/providers/auth0.rb
Overview
This class adds support for OAuth with Auth0.com
config.auth0.key = <key>
config.auth0.secret = <secret>
config.auth0.domain = <domain>
...
Instance Attribute Summary collapse
-
#auth_path ⇒ Object
Returns the value of attribute auth_path.
-
#scope ⇒ Object
Returns the value of attribute scope.
-
#token_path ⇒ Object
Returns the value of attribute token_path.
-
#user_info_path ⇒ Object
Returns the value of attribute user_info_path.
Attributes inherited from Base
#access_token, #callback_url, #key, #original_callback_url, #secret, #site, #state, #user_info_mapping
Instance Method Summary collapse
- #get_user_hash(access_token) ⇒ Object
-
#initialize ⇒ Auth0
constructor
A new instance of Auth0.
- #login_url(_params, _session) ⇒ Object
- #process_callback(params, _session) ⇒ Object
Methods included from Sorcery::Protocols::Oauth2
#authorize_url, #build_client, #get_access_token, #oauth_version
Methods inherited from Base
#auth_hash, descendants, #has_callback?, name
Constructor Details
#initialize ⇒ Auth0
Returns a new instance of Auth0.
15 16 17 18 19 20 21 22 |
# File 'lib/sorcery/providers/auth0.rb', line 15 def initialize super @auth_path = '/authorize' @token_path = '/oauth/token' @user_info_path = '/userinfo' @scope = 'openid profile email' end |
Instance Attribute Details
#auth_path ⇒ Object
Returns the value of attribute auth_path.
13 14 15 |
# File 'lib/sorcery/providers/auth0.rb', line 13 def auth_path @auth_path end |
#scope ⇒ Object
Returns the value of attribute scope.
13 14 15 |
# File 'lib/sorcery/providers/auth0.rb', line 13 def scope @scope end |
#token_path ⇒ Object
Returns the value of attribute token_path.
13 14 15 |
# File 'lib/sorcery/providers/auth0.rb', line 13 def token_path @token_path end |
#user_info_path ⇒ Object
Returns the value of attribute user_info_path.
13 14 15 |
# File 'lib/sorcery/providers/auth0.rb', line 13 def user_info_path @user_info_path end |
Instance Method Details
#get_user_hash(access_token) ⇒ Object
24 25 26 27 28 29 30 31 |
# File 'lib/sorcery/providers/auth0.rb', line 24 def get_user_hash(access_token) response = access_token.get(user_info_path) auth_hash(access_token).tap do |h| h[:user_info] = JSON.parse(response.body) h[:uid] = h[:user_info]['sub'] end end |
#login_url(_params, _session) ⇒ Object
33 34 35 |
# File 'lib/sorcery/providers/auth0.rb', line 33 def login_url(_params, _session) (authorize_url: auth_path) end |
#process_callback(params, _session) ⇒ Object
37 38 39 40 41 42 43 |
# File 'lib/sorcery/providers/auth0.rb', line 37 def process_callback(params, _session) args = {}.tap do |a| a[:code] = params[:code] if params[:code] end get_access_token(args, token_url: token_path, token_method: :post) end |