Class: OmniAuth::Strategies::Doximity
- Inherits:
-
OAuth
- Object
- OAuth
- OmniAuth::Strategies::Doximity
- Defined in:
- lib/omniauth/strategies/doximity.rb
Instance Attribute Summary collapse
-
#profile ⇒ Object
readonly
Returns the value of attribute profile.
Instance Method Summary collapse
- #callback_phase ⇒ Object
- #exchange_code(code) ⇒ Object
- #request_phase ⇒ Object
- #user_profile(code) ⇒ Object
Instance Attribute Details
#profile ⇒ Object (readonly)
Returns the value of attribute profile.
20 21 22 |
# File 'lib/omniauth/strategies/doximity.rb', line 20 def profile @profile end |
Instance Method Details
#callback_phase ⇒ Object
38 39 40 41 42 |
# File 'lib/omniauth/strategies/doximity.rb', line 38 def callback_phase @profile = user_profile(request.params['code']) self.env['omniauth.auth'] = auth_hash call_app! end |
#exchange_code(code) ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/omniauth/strategies/doximity.rb', line 44 def exchange_code(code) redirect_uri = URI(.redirect_uri) redirect_uri.query = request.params.except('code').to_query uri = URI::HTTPS.build( host: ..site, path: ..token_path ) req = Net::HTTP::Post.new(uri.to_s) req.set_form_data( client_id: consumer.key, client_secret: consumer.secret, redirect_uri: redirect_uri.to_s, grant_type: .grant_type, code: code ) res = Net::HTTP.start(uri.host, uri.port, :use_ssl => uri.scheme == 'https') do |http| http.request(req) end JSON.parse(res.body) end |
#request_phase ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/omniauth/strategies/doximity.rb', line 22 def request_phase redirect_uri = URI(.redirect_uri) redirect_uri.query = request.params.to_query uri = URI::HTTPS.build( host: ..site, path: .., query: { client_id: consumer.key, redirect_uri: redirect_uri.to_s, response_type: .response_type, scope: .scope }.to_query ) redirect uri.to_s end |
#user_profile(code) ⇒ Object
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/omniauth/strategies/doximity.rb', line 68 def user_profile(code) token_exchange = exchange_code(code) uri = URI::HTTPS.build( host: ..site, path: ..profile_path, query: { access_token: token_exchange['access_token'] }.to_query ) req = Net::HTTP::Get.new(uri.to_s) res = Net::HTTP.start(uri.host, uri.port, :use_ssl => uri.scheme == 'https') do |http| http.request(req) end JSON.parse(res.body).merge('token_exchange' => token_exchange) end |