Last active
May 10, 2020 18:59
-
-
Save handylearn/6d6125263d32544c2057 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'omniauth-oauth2' | |
# this OmniAuth-Strategy uses the Keyrock Identity Management | |
# see http://catalogue.fiware.org/enablers/identity-management-keyrock | |
# The server url is from the public FIWARE Lab instance. | |
module OmniAuth | |
module Strategies | |
class FilabStrategy < OmniAuth::Strategies::OAuth2 | |
option :name, "filab" | |
option :client_options, { | |
:site => 'https://account.lab.fiware.org', | |
:authorize_url => 'https://account.lab.fiware.org/oauth2/authorize/', | |
:token_url => 'https://account.lab.fiware.org/oauth2/token' | |
} | |
uid { raw_info['id'].to_s } | |
info do | |
{ | |
'nickname' => raw_info['nickName'], | |
'email' => raw_info['email'], | |
'name' => raw_info['displayName'], | |
} | |
end | |
extra do | |
{:raw_info => raw_info} | |
end | |
def raw_info | |
access_token.options[:mode] = :query | |
@raw_info ||= access_token.get('user.json', params: { access_token: access_token.token }).parsed | |
end | |
def build_access_token | |
Rails.logger.debug "Omniauth build access token" | |
options.token_params.merge!(:headers => {'Authorization' => basic_auth_header }) | |
super | |
end | |
def basic_auth_header | |
"Basic " + Base64.strict_encode64("#{options[:client_id]}:#{options[:client_secret]}") | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@handylearn You could avoid the line 37 with a option like this