Sha256: 20309fa4037c32b399b51265330d67a9d765192834a5cb5e7b3082c4be13388c

Contents?: true

Size: 1.25 KB

Versions: 1

Compression:

Stored size: 1.25 KB

Contents

require 'omniauth-oauth2'
require 'jwt'

module OmniAuth
	module Strategies
		class Edenred < OmniAuth::Strategies::OAuth2
		
			option :name, 'edenred'
			option :sandbox, false

			option :client_options, {
				:site => 'https://sso.auth.api.edenred.com/idsrv',
				:authorize_url => 'https://sso.auth.api.edenred.com/idsrv/connect/authorize',
				:token_url => 'https://sso.auth.api.edenred.com/idsrv/connect/token',
			}

			def setup_phase
				super

				if options[:sandbox] === true
					options[:client_options] = {
						:site => 'https://sso.auth-sandbox.api.edenred.com/idsrv',
						:authorize_url => 'https://sso.auth-sandbox.api.edenred.com/idsrv/connect/authorize',
						:token_url => 'https://sso.auth-sandbox.api.edenred.com/idsrv/connect/token',
					}
				end
			end

			uid { raw_info['username'] }

			info do
				{
					:name => raw_info['username'],
					:email => raw_info['username'],
				}
			end

			extra do
				{
					'raw_info' => raw_info
				}
			end

			def raw_info
				@raw_info ||= JWT.decode(access_token.params['id_token'], nil, false).first
			end

			# Required for omniauth-oauth2 >= 1.4
			# https://github.com/intridea/omniauth-oauth2/issues/81
			def callback_url
				full_host + script_name + callback_path
			end

		end
	end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
omniauth-edenred-1.0.0 lib/omniauth/strategies/edenred.rb