Skip to content

Instantly share code, notes, and snippets.

@tachyons
Forked from handylearn/filab_strategy.rb
Created March 12, 2016 16:07
Show Gist options
  • Save tachyons/260777672941a3e86720 to your computer and use it in GitHub Desktop.
Save tachyons/260777672941a3e86720 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment