Module: AuthTool
- Defined in:
- lib/auth_tool.rb,
lib/auth_tool/client.rb,
lib/auth_tool/oauth_1.rb,
lib/auth_tool/oauth_2.rb,
lib/auth_tool/version.rb
Defined Under Namespace
Modules: OAuth1, OAuth2 Classes: Client
Constant Summary collapse
- VERSION =
"1.0.0"
Class Method Summary collapse
-
.call(client, http_verb, uri, params = {}) ⇒ Hash
Makes an authenticated call to the API resource.
-
.get_client(client_secrets) ⇒ AuthTool::Client
Creates a client object for the specified API.
-
.get_redirect_url(client) ⇒ String
Returns the redirect url so the user can authenticate with the service.
-
.get_token(client) ⇒ Hash
Returns the authentication token information of the client.
-
.receive(client, response) ⇒ Object
Handles service’s user authentication response delivered by the front-end.
-
.refresh(client) ⇒ Object
Attempts to refresh the auth token for the client.
Class Method Details
.call(client, http_verb, uri, params = {}) ⇒ Hash
Makes an authenticated call to the API resource.
83 84 85 86 |
# File 'lib/auth_tool.rb', line 83 def self.call(client, http_verb, uri, params = {}) response = client.oauth_version == 1 ? AuthTool::OAuth1.call(client, http_verb, uri, params) : AuthTool::OAuth2.call(client, http_verb, uri, params) return response end |
.get_client(client_secrets) ⇒ AuthTool::Client
Creates a client object for the specified API.
13 14 15 16 17 |
# File 'lib/auth_tool.rb', line 13 def self.get_client client_secrets raise "Expected Hash, received #{client_secrets.class}" if client_secrets.class != Hash client = create_client(client_secrets) return client end |
.get_redirect_url(client) ⇒ String
Returns the redirect url so the user can authenticate with the service.
26 27 28 29 30 31 |
# File 'lib/auth_tool.rb', line 26 def self.get_redirect_url client params = client.params if client.has_params? params ||= {} redirect_url = client.oauth_version == 1 ? AuthTool::OAuth1.redirect_url(client, params) : AuthTool::OAuth2.redirect_url(client) return redirect_url end |
.get_token(client) ⇒ Hash
Returns the authentication token information of the client
53 54 55 |
# File 'lib/auth_tool.rb', line 53 def self.get_token client return client.token end |
.receive(client, response) ⇒ Object
Handles service’s user authentication response delivered by the front-end. Sets the client’s access_token.
42 43 44 |
# File 'lib/auth_tool.rb', line 42 def self.receive(client, response) client.oauth_version == 1 ? AuthTool::OAuth1.receive(client, response) : AuthTool::OAuth2.receive(client,response) end |
.refresh(client) ⇒ Object
Attempts to refresh the auth token for the client
61 62 63 |
# File 'lib/auth_tool.rb', line 61 def self.refresh client client.refresh end |