Sha256: b69e67fe3e24e109a18fe3a57bd2caa6b1a2dc53c060c2284ddc66001c85b207
Contents?: true
Size: 1.37 KB
Versions: 1
Compression:
Stored size: 1.37 KB
Contents
require 'omniauth-oauth2' require 'graphql/client' require 'graphql/client/http' require 'intercode_client' module OmniAuth module Strategies class Intercode < OmniAuth::Strategies::OAuth2 CurrentUserQuery = IntercodeClient::Client.parse <<~GRAPHQL query IntercodeClientCurrentUserQuery { currentUser { id first_name last_name email } } GRAPHQL # Give your strategy a name. option :name, 'intercode' # This is where you pass the options you would pass when # initializing your consumer from the OAuth gem. option :client_options, site: IntercodeClient.intercode_url uid do decoded_jwt['user']['id'] end info do { first_name: raw_info.data.current_user.first_name, last_name: raw_info.data.current_user.last_name, email: raw_info.data.current_user.email } end extra do { 'access_token' => access_token.token, 'raw_info' => raw_info.to_h } end def raw_info @raw_info ||= IntercodeClient::Client.query( CurrentUserQuery, context: { headers: access_token.headers } ) end def decoded_jwt @decoded_jwt ||= IntercodeClient.decode_jwt(access_token.token) end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
intercode_client-0.1.0 | lib/omniauth/strategies/intercode.rb |