Module: GDS::SSO::BearerToken
- Defined in:
- lib/gds-sso/bearer_token.rb
Class Method Summary collapse
- .locate(token_string) ⇒ Object
- .oauth_client ⇒ Object
-
.omniauth_style_response(response_body) ⇒ Object
Our User code assumes we’re getting our user data back via omniauth and so receiving it in omniauth’s preferred structure.
Class Method Details
.locate(token_string) ⇒ Object
7 8 9 10 11 12 13 14 |
# File 'lib/gds-sso/bearer_token.rb', line 7 def self.locate(token_string) access_token = OAuth2::AccessToken.new(oauth_client, token_string) response_body = access_token.get("/user.json?client_id=#{CGI.escape(GDS::SSO::Config.oauth_id)}").body user_details = omniauth_style_response(response_body) GDS::SSO::Config.user_klass.find_for_gds_oauth(user_details) rescue OAuth2::Error nil end |
.oauth_client ⇒ Object
16 17 18 19 20 21 22 |
# File 'lib/gds-sso/bearer_token.rb', line 16 def self.oauth_client @oauth_client ||= OAuth2::Client.new( GDS::SSO::Config.oauth_id, GDS::SSO::Config.oauth_secret, :site => GDS::SSO::Config.oauth_root_url ) end |
.omniauth_style_response(response_body) ⇒ Object
Our User code assumes we’re getting our user data back via omniauth and so receiving it in omniauth’s preferred structure. Here we’re addressing signonotron directly so we need to transform the response ourselves.
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/gds-sso/bearer_token.rb', line 28 def self.omniauth_style_response(response_body) input = MultiJson.decode(response_body)['user'] { 'uid' => input['uid'], 'info' => { 'email' => input['email'], 'name' => input['name'] }, 'extra' => { 'user' => { 'permissions' => input['permissions'], 'organisation_slug' => input['organisation_slug'], } } } end |