Class: OmniAuth::Strategies::DNSimple
- Inherits:
-
OAuth2
- Object
- OAuth2
- OmniAuth::Strategies::DNSimple
- Defined in:
- lib/omniauth/strategies/dnsimple.rb
Instance Method Summary collapse
-
#build_access_token ⇒ Object
Override the build_access_token method to manually handle the token request.
- #callback_url ⇒ Object
-
#request_phase ⇒ Object
Override method in OmniAuth::Strategies::OAuth2 to error when we don’t have a client_id or secret.
Instance Method Details
#build_access_token ⇒ Object
Override the build_access_token method to manually handle the token request
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 |
# File 'lib/omniauth/strategies/dnsimple.rb', line 72 def build_access_token code = request.params['code'] state = request.params['state'] # Create the token request manually uri = URI.parse(..token_url) http = Net::HTTP.new(uri.host, uri.port) http.use_ssl = true request = Net::HTTP::Post.new(uri.path) request.set_form_data({ 'grant_type' => 'authorization_code', 'client_id' => .client_id, 'client_secret' => .client_secret, 'code' => code, 'redirect_uri' => callback_url, 'state' => state }) response = http.request(request) if response.code.to_i == 200 data = JSON.parse(response.body) ::OAuth2::AccessToken.from_hash(client, data) else error_msg = "Failed to get access token: #{response.code} - #{response.body}" raise ::OAuth2::Error.new(OpenStruct.new(status: response.code, body: response.body)) end end |
#callback_url ⇒ Object
55 56 57 |
# File 'lib/omniauth/strategies/dnsimple.rb', line 55 def callback_url [:redirect_uri] || (full_host + callback_path) end |
#request_phase ⇒ Object
Override method in OmniAuth::Strategies::OAuth2 to error when we don’t have a client_id or secret
61 62 63 64 65 66 67 68 69 |
# File 'lib/omniauth/strategies/dnsimple.rb', line 61 def request_phase if missing_client_id? fail!(:missing_client_id) elsif missing_client_secret? fail!(:missing_client_secret) else super end end |