Sha256: d058053fa02ed18f6f38197371b029931d86f2b716f7dca734fab1f3a699fd69

Contents?: true

Size: 1.58 KB

Versions: 5

Compression:

Stored size: 1.58 KB

Contents

require "omniauth-oauth2"

module OmniAuth
  module Strategies
    class Auth0 < OmniAuth::Strategies::OAuth2
      PASSTHROUGHS = %w[
        connection
        redirect_uri
      ]

      option :name, "auth0"
      option :namespace, nil
      option :provider_ignores_state, true

      args [:client_id, :client_secret, :namespace, :provider_ignores_state]

      def initialize(app, *args, &block)
        super
        @options.provider_ignores_state = args[3] unless args[3].nil?

        @options.client_options.site          = "https://#{options[:namespace]}"
        @options.client_options.authorize_url = "https://#{options[:namespace]}/authorize"
        @options.client_options.token_url     = "https://#{options[:namespace]}/oauth/token"
        @options.client_options.userinfo_url  = "https://#{options[:namespace]}/userinfo"
      end

      def authorize_params
        super.tap do |param|
          PASSTHROUGHS.each do |p|
            param[p.to_sym] = request.params[p] if request.params[p]
          end
        end
      end

      uid { raw_info["user_id"] }

      extra do
        { :raw_info => raw_info }
      end

      info do
        {
          :name => raw_info["name"],
          :email => raw_info["email"],
          :nickname => raw_info["nickname"],
          :first_name => raw_info["given_name"],
          :last_name => raw_info["family_name"],
          :location => raw_info["locale"],
          :image => raw_info["picture"]
        }
      end

      def raw_info
        @raw_info ||= access_token.get(options.client_options.userinfo_url).parsed
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 2 rubygems

Version Path
omniauth-auth0-1.0.2 lib/omniauth/strategies/auth0.rb
omniauth-auth0-1.0.1 lib/omniauth/strategies/auth0.rb
omniauth-auth0-1.0.0 lib/omniauth/strategies/auth0.rb
auth0-1.0.0 lib/omniauth/strategies/auth0.rb
auth0-0.1.2 lib/omniauth/strategies/auth0.rb