Skip to content

Instantly share code, notes, and snippets.

@handylearn
Last active May 10, 2020 18:59
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save handylearn/6d6125263d32544c2057 to your computer and use it in GitHub Desktop.
Save handylearn/6d6125263d32544c2057 to your computer and use it in GitHub Desktop.
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
@handylearn
Copy link
Author

Changed to new hostname (fiware instead if fi-ware)

@gurgelrenan
Copy link

gurgelrenan commented Aug 12, 2016

@handylearn You could avoid the line 37 with a option like this

option :token_params, {
    :headers => {'Authorization' => "Basic " + Base64.strict_encode64("client_id:client_secret") }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment