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.2"
Class Method Summary collapse
-
.call(client, http_verb, uri, params = {}) ⇒ Hash
Makes an authenticated call to the API resource.
-
.get_client(client_secrets, token = {}) ⇒ 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.
84 85 86 87 |
# File 'lib/auth_tool.rb', line 84 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, token = {}) ⇒ AuthTool::Client
Creates a client object for the specified API.
13 14 15 16 17 18 |
# File 'lib/auth_tool.rb', line 13 def self.get_client(client_secrets, token = {}) raise "Expected Hash, received #{client_secrets.class}" if client_secrets.class != Hash client = create_client(client_secrets) if token == {} client = create_client(client_secrets, token) if token != {} return client end |
.get_redirect_url(client) ⇒ String
Returns the redirect url so the user can authenticate with the service.
27 28 29 30 31 32 |
# File 'lib/auth_tool.rb', line 27 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
54 55 56 |
# File 'lib/auth_tool.rb', line 54 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.
43 44 45 |
# File 'lib/auth_tool.rb', line 43 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
62 63 64 |
# File 'lib/auth_tool.rb', line 62 def self.refresh client client.refresh end |