Sha256: 60c70c5d7572abbdadf85d6bf7bc705bd38a44e22ed6e7d8e588605739062c6a

Contents?: true

Size: 1.13 KB

Versions: 11

Compression:

Stored size: 1.13 KB

Contents

module Sorcery
  module Providers
    # This class adds support for OAuth with Auth0.com
    #
    #   config.auth0.key = <key>
    #   config.auth0.secret = <secret>
    #   config.auth0.domain = <domain>
    #   ...
    #
    class Auth0 < Base
      include Protocols::Oauth2

      attr_accessor :auth_path, :token_path, :user_info_path, :scope

      def initialize
        super

        @auth_path      = '/authorize'
        @token_path     = '/oauth/token'
        @user_info_path = '/userinfo'
        @scope          = 'openid profile email'
      end

      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

      def login_url(_params, _session)
        authorize_url(authorize_url: auth_path)
      end

      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
    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
sorcery-0.17.0 lib/sorcery/providers/auth0.rb
sorcery-0.16.5 lib/sorcery/providers/auth0.rb
sorcery-0.16.4 lib/sorcery/providers/auth0.rb
sorcery-0.16.3 lib/sorcery/providers/auth0.rb
sorcery-0.16.2 lib/sorcery/providers/auth0.rb
sorcery-0.16.1 lib/sorcery/providers/auth0.rb
sorcery-0.15.1 lib/sorcery/providers/auth0.rb
sorcery-0.16.0 lib/sorcery/providers/auth0.rb
sorcery-0.15.0 lib/sorcery/providers/auth0.rb
sorcery-0.14.0 lib/sorcery/providers/auth0.rb
sorcery-0.13.0 lib/sorcery/providers/auth0.rb