Class: Plangrade::OAuth2Client
- Inherits:
-
OAuth2Client::Client
- Object
- OAuth2Client::Client
- Plangrade::OAuth2Client
- Defined in:
- lib/plangrade/oauth2_client.rb
Constant Summary collapse
- SITE_URL =
'https://plangrade.com'- TOKEN_PATH =
'/oauth/token'- AUTHORIZE_PATH =
'/oauth/authorize'
Instance Method Summary collapse
-
#exchange_auth_code_for_token(opts = {}) ⇒ Object
client_id=Configurable#client_id&code=G3Y6jU3a&grant_type=authorization_code& redirect_uri=http%3A%2F%2Flocalhost%3A3000%2Fauth%2Fplangrade%2Fcallback&client_secret=Configurable#client_secret.
-
#initialize(client_id, client_secret, opts = {}) {|_self| ... } ⇒ OAuth2Client
constructor
A new instance of OAuth2Client.
-
#refresh_access_token(opts = {}) ⇒ Object
client_id=Configurable#client_id&refresh_token=G3Y6jU3a&grant_type=refresh_token& client_secret=Configurable#client_secret.
-
#webserver_authorization_url(opts = {}) ⇒ Object
Generates the Plangrade URL that the user will be redirected to in order to authorize your application.
Constructor Details
#initialize(client_id, client_secret, opts = {}) {|_self| ... } ⇒ OAuth2Client
Returns a new instance of OAuth2Client.
10 11 12 13 14 15 16 17 |
# File 'lib/plangrade/oauth2_client.rb', line 10 def initialize(client_id, client_secret, opts={}) site_url = opts.delete(:site_url) || SITE_URL opts[:token_path] ||= TOKEN_PATH opts[:authorize_path] ||= AUTHORIZE_PATH super(site_url, client_id, client_secret, opts) yield self if block_given? self end |
Instance Method Details
#exchange_auth_code_for_token(opts = {}) ⇒ Object
client_id=Configurable#client_id&code=G3Y6jU3a&grant_type=authorization_code&
redirect_uri=http%3A%2F%2Flocalhost%3A3000%2Fauth%2Fplangrade%2Fcallback&client_secret={client_secret}
57 58 59 60 61 62 63 64 |
# File 'lib/plangrade/oauth2_client.rb', line 57 def exchange_auth_code_for_token(opts={}) unless (opts[:params] && opts[:params][:code]) raise ArgumentError.new("You must include an authorization code as a parameter") end opts[:authenticate] ||= :body code = opts[:params].delete(:code) .get_token(code, opts) end |
#refresh_access_token(opts = {}) ⇒ Object
client_id=Configurable#client_id&refresh_token=G3Y6jU3a&grant_type=refresh_token&
client_secret={client_secret}
84 85 86 87 88 89 90 91 |
# File 'lib/plangrade/oauth2_client.rb', line 84 def refresh_access_token(opts={}) unless (opts[:params] && opts[:params][:refresh_token]) raise ArgumentError.new("You must provide a refresh_token as a parameter") end opts[:authenticate] = :body token = opts[:params].delete(:refresh_token) refresh_token.get_token(token, opts) end |
#webserver_authorization_url(opts = {}) ⇒ Object
Generates the Plangrade URL that the user will be redirected to in order to authorize your application
>> client = Plangrade::OAuth2Client.new(‘ETSIGVSxmgZitijWZr0G6w’, ‘4bJZY38TCBB9q8IpkeualA2lZsPhOSclkkSKw3RXuE’) >> client.webserver_authorization_url({
:redirect_uri => 'http://localhost:3000/auth/plangrade/callback',
})
>> plangrade.com/oauth/authorize/?client_id=Configurable#client_id&
redirect_uri=http%3A%2F%2Flocalhost%3A3000%2Fauth%2Fplangrade%2Fcallback&response_type=code
33 34 35 36 |
# File 'lib/plangrade/oauth2_client.rb', line 33 def (opts={}) opts[:scope] = normalize_scope(opts[:scope]) if opts[:scope] .(opts) end |