Class: LinkedIn::OAuth2
- Inherits:
-
OAuth2::Client
- Object
- OAuth2::Client
- LinkedIn::OAuth2
- Defined in:
- lib/linked_in/oauth2.rb
Overview
The LinkedIn::OAuth2::Client class. Inherits directly from intreda/oauth2's OAuth2::Client
LinkedIn::OAuth2 sets the following default options:
- site = "https://www.linkedin.com"
- token_url = "/uas/oauth2/accessToken"
- authorize_url = "/uas/oauth2/authorization"
More details on LinkedIn's Authorization process can be found here: https://developer.linkedin.com/documents/authentication
Instance Attribute Summary collapse
-
#access_token ⇒ Object
Returns the value of attribute access_token.
Instance Method Summary collapse
-
#auth_code_url(options = {}) ⇒ Object
Generates the URL users use to sign into your application.
-
#get_access_token(code = nil, options = {}) ⇒ Object
Returns the access token string for the newly authenticated user.
-
#initialize(client_id = LinkedIn.config.client_id, client_secret = LinkedIn.config.client_secret, options = {}) {|builder| ... } ⇒ OAuth2
constructor
Instantiate a new OAuth 2.0 client using your client ID (aka API Key) and client secret (aka Secret Key).
Constructor Details
#initialize(client_id = LinkedIn.config.client_id, client_secret = LinkedIn.config.client_secret, options = {}) {|builder| ... } ⇒ OAuth2
Instantiate a new OAuth 2.0 client using your client ID (aka API Key) and client secret (aka Secret Key).
You should set the client_id and client_secret in the config.
LinkedIn.configure do |config|
config.client_id = ENV["LINKEDIN_CLIENT_ID"]
config.client_secret = ENV["LINKEDIN_CLIENT_SECRET"]
end
This will let you initialize with zero arguments.
If you have already set the client_id
and client_secret
in your
config, the first and only argument can be the options
hash.
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/linked_in/oauth2.rb', line 42 def initialize(client_id=LinkedIn.config.client_id, client_secret=LinkedIn.config.client_secret, = {}, &block) if client_id.is_a? Hash = client_id client_id = LinkedIn.config.client_id end = () super client_id, client_secret, , &block @redirect_uri = [:redirect_uri] if self.[:raise_errors] check_credentials!(client_id, client_secret) end end |
Instance Attribute Details
#access_token ⇒ Object
Returns the value of attribute access_token.
13 14 15 |
# File 'lib/linked_in/oauth2.rb', line 13 def access_token @access_token end |
Instance Method Details
#auth_code_url(options = {}) ⇒ Object
Generates the URL users use to sign into your application.
Once a user enters their LinkedIn credentials, they will be
redirected to your redirect_uri
with the code
parameter attached
to it. The value of the code
parameter can be used to get an
access token.
We recommend you set your client_id,
client_secret, and
redirect_uriin the
LinkedIn.configure` block. They can also be
passed in as options.
90 91 92 93 94 95 96 97 98 99 100 |
# File 'lib/linked_in/oauth2.rb', line 90 def auth_code_url(={}) = () if self.[:raise_errors] check_redirect_uri!() end @redirect_uri = [:redirect_uri] self.auth_code.() end |
#get_access_token(code = nil, options = {}) ⇒ Object
Returns the access token string for the newly authenticated user.
It also sets the access_token
field on this LinkedIn::OAuth2
instance.
The required code
120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 |
# File 'lib/linked_in/oauth2.rb', line 120 def get_access_token(code=nil, ={}) check_for_code!(code) = () if self.[:raise_errors] check_access_code_url!() end tok = self.auth_code.get_token(code, ) self.access_token = LinkedIn::AccessToken.new(tok.token, tok.expires_in, tok.expires_at) return self.access_token rescue ::OAuth2::Error => e raise OAuthError.new(e.response) end |