Module: LinkedIn::Helpers::Authorization
- Included in:
- Client
- Defined in:
- lib/linked_in/helpers/authorization.rb
Constant Summary collapse
- DEFAULT_OAUTH2_OPTIONS =
{ authorize_path: "/uas/oauth2/authorization", access_token_path: "/uas/oauth2/accessToken", api_host: "https://api.linkedin.com", auth_host: "https://www.linkedin.com" }
Instance Method Summary collapse
-
#authorize_url(params = {}) ⇒ Object
A way to fetch the authorize_url request.
- #oauth2_client ⇒ Object
-
#request_access_token(code, params = {}) ⇒ Object
Fetches the access_token given the auth_code fetched by navigating to ‘authorize_url` fetched the token.
-
#set_access_token(token, options = {}) ⇒ Object
If one already has an access_token string, it can be set here and turned into an OAuth2::AccessToken object.
Instance Method Details
#authorize_url(params = {}) ⇒ Object
A way to fetch the authorize_url request.
47 48 49 50 51 52 53 54 55 56 |
# File 'lib/linked_in/helpers/authorization.rb', line 47 def (params={}) # response_type param included by default by using the OAuth 2.0 # auth_code strategy # client_id param included automatically by the OAuth 2.0 gem params[:state] ||= state params[:redirect_uri] ||= "http://localhost" oauth2_client.auth_code.(params) rescue OAuth2::Error => e raise LinkedIn::Errors::UnauthorizedError.new(e.code), e.description end |
#oauth2_client ⇒ Object
37 38 39 40 41 |
# File 'lib/linked_in/helpers/authorization.rb', line 37 def oauth2_client @oauth2_client ||= ::OAuth2::Client.new(@client_id, @client_secret, ) end |
#request_access_token(code, params = {}) ⇒ Object
Fetches the access_token given the auth_code fetched by navigating to ‘authorize_url` fetched the token.
62 63 64 65 66 67 68 69 70 |
# File 'lib/linked_in/helpers/authorization.rb', line 62 def request_access_token(code, params={}) params[:redirect_uri] ||= "http://localhost" opts = {} opts[:mode] = :query opts[:param_name] = "oauth2_access_token" @access_token = oauth2_client.auth_code.get_token(code, params, opts) rescue OAuth2::Error => e raise LinkedIn::Errors::UnauthorizedError.new(e.code), e.description end |
#set_access_token(token, options = {}) ⇒ Object
If one already has an access_token string, it can be set here and turned into an OAuth2::AccessToken object.
74 75 76 77 78 79 |
# File 'lib/linked_in/helpers/authorization.rb', line 74 def set_access_token(token, ={}) [:access_token] = token [:mode] = :query [:param_name] = "oauth2_access_token" @access_token = OAuth2::AccessToken.from_hash oauth2_client, end |