Class: Plangrade::OAuth2Client

Inherits:
OAuth2Client::Client
  • Object
show all
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

Constructor Details

#initialize(client_id, client_secret, opts = {}) {|_self| ... } ⇒ OAuth2Client

Returns a new instance of OAuth2Client.

Yields:

  • (_self)

Yield Parameters:



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

#access_token_from_authorization_code(code, 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}


74
75
76
77
# File 'lib/plangrade/oauth2_client.rb', line 74

def access_token_from_authorization_code(code, opts={})
  opts[:authenticate] ||= :body
  authorization_code.get_token(code, opts)
end

#webclient_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.webclient_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%2F%2Fplangrade%2Fcallback&response_type=token


33
34
35
# File 'lib/plangrade/oauth2_client.rb', line 33

def webclient_authorization_url(opts={})
  implicit.token_url(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


51
52
53
54
# File 'lib/plangrade/oauth2_client.rb', line 51

def webserver_authorization_url(opts={})
  opts[:scope] = normalize_scope(opts[:scope]) if opts[:scope]
  authorization_code.authorization_url(opts)
end