auth_tool 0.1.0 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5d56792e99a023ce052116b150b3bc522ffc6056
4
- data.tar.gz: c4f27a14ea74ddcc4399315c8f04958df1338991
3
+ metadata.gz: 70920dcd4afbb68a32b3195629f9fb62a042326f
4
+ data.tar.gz: 3be6cf4fd1567d7452a48a674a1ee336cf7ec550
5
5
  SHA512:
6
- metadata.gz: 1e3de273379e2ac32cfece719ea7d047337391258fec315fd489b8ac437dfa7c83598d557575ff5062b1281a635f0c80079b974133abcac5b00a8c188be5d19c
7
- data.tar.gz: 37b3e51fc31bda161153a959bc5b5df44bf496f2a54ccfe216a71e30fc322dc95b87e8171e47b38feeb32b071cda517c7e46a02a17a626d05ee56cdd8357f06f
6
+ metadata.gz: ed388c1d6a97eacfa9fd7fa6b39d990892ad0efd56a71f7b4670e7cad80608dc8a5e9040350ee52fd098b737e6e30bf78abd48cf01cc4685daabdd28a8eaf7f4
7
+ data.tar.gz: 4c76d3c359f7d537751d4e7b24f359fc440c2f8e97621ad6ad2c06cbc884353a510d86405685023e2c6c30573f121021d869e0cf90191dc629c8f0a9d9aeeac9
@@ -1,6 +1,8 @@
1
1
  require 'sinatra'
2
- require_relative '../auth_tool'
3
- client = AuthTool::get_client 'twitter'
2
+ require_relative '../lib/auth_tool'
3
+ #client = AuthTool::get_client 'twitter'
4
+ client = AuthTool::get_client({"temporary_credential_uri" => "https://api.twitter.com/oauth/request_token", "authorization_uri" => "https://api.twitter.com/oauth/authorize", "token_credential_uri" => "https://api.twitter.com/oauth/access_token", "client_credential_key" => "ajkMgzvyhFwZV9hBgQjlW0rrG", "client_credential_secret" => "BKorJt4MRMpGxCGXNWGz0nFBhd7XfRx3vOHQpL24LKImcLlKXU", "callback" => "http://localhost:4567/callback", "verifier" => "oauth_verifier", "oauth_version" => "1" })
5
+
4
6
  get '/' do
5
7
  redirect AuthTool::get_redirect_url client
6
8
  end
@@ -1,6 +1,7 @@
1
1
  require 'sinatra'
2
- require_relative '../auth_tool'
3
- client = AuthTool::get_client 'github'
2
+ require_relative '../lib/auth_tool'
3
+ #client = AuthTool::get_client 'github'
4
+ client = AuthTool::get_client JSON.parse({ "client_id":"c1d4265302eba1aa4f37", "authorization_uri":"https://github.com/login/oauth/authorize", "token_credential_uri":"https://github.com/login/oauth/access_token", "client_secret":"7be3891166bdfc95193b20bf3e65dbf0844e2121", "oauth_version": "2", "redirect_uri": "http://localhost:4567/callback", "scope": "user" })
4
5
  get '/' do
5
6
  redirect AuthTool::get_redirect_url client
6
7
  end
@@ -9,8 +9,11 @@ module AuthTool
9
9
  #
10
10
  # @param [Hash] options
11
11
  # Configuration parameters for the client.
12
- def initialize(options, *credentials)
12
+ def initialize(options, *args)
13
13
  config = options
14
+ credentials = args[0] if args.length == 1
15
+ credentials ||= {}
16
+ raise "Too many args" if args.length > 1
14
17
  @has_params = config.has_key?('params')
15
18
  self.oauth_version = config.delete('oauth_version')
16
19
  self.params = config.delete('params') if @has_params
@@ -21,7 +24,7 @@ module AuthTool
21
24
  elsif @oauth_version == 2
22
25
  oauth2 config
23
26
  self.signet.access_token = credentials["oauth_token"] if credentials.has_key? "oauth_token"
24
- self.signet.refresh_token = credentials["refresh_token"] if credentialsl.has_key? "refresh_token"
27
+ self.signet.refresh_token = credentials["refresh_token"] if credentialsl.has_key? "refresh_token"
25
28
  else
26
29
  raise "Unexpected oauth_version: #{@oauth_version}"
27
30
  end
@@ -1,5 +1,6 @@
1
1
  require_relative 'client'
2
2
  require 'json'
3
+ require 'faraday'
3
4
 
4
5
  module AuthTool
5
6
  module OAuth1
@@ -61,7 +62,7 @@ module AuthTool
61
62
  def self.call(client, http_verb = 'get', uri, params)
62
63
  header = params.delete('header') if params.has_key? 'header'
63
64
  body = params.delete('body') if params.has_key? 'body'
64
- conn = AuthTool::Helper.get_connection(params)
65
+ conn = Faraday.new(:params => params)
65
66
  options = {:method => http_verb, :header => header, :body => body, :uri => uri, :connection => conn}
66
67
  response = client.signet.fetch_protected_resource(options)
67
68
  return JSON.parse(response.body)
@@ -1,3 +1,4 @@
1
+ require 'faraday'
1
2
  require_relative 'client'
2
3
 
3
4
  module AuthTool
@@ -50,7 +51,7 @@ module AuthTool
50
51
  def self.call(client,http_verb = 'get', uri, params)
51
52
  header = params.delete('header') if params.has_key? 'header'
52
53
  body = params.delete('body') if params.has_key? 'body'
53
- conn = AuthTool::Helper.get_connection(params)
54
+ conn = Faraday.new(:params => params)
54
55
  options = {:method => http_verb, :header => header, :body => body, :uri => uri, :connection => conn}
55
56
  response = client.signet.fetch_protected_resource(options)
56
57
  return JSON.parse(response.body)
@@ -1,3 +1,3 @@
1
1
  module AuthTool
2
- VERSION = "0.1.0"
2
+ VERSION = "1.0.0"
3
3
  end
data/lib/auth_tool.rb CHANGED
@@ -1,5 +1,4 @@
1
1
  require_relative 'auth_tool/client'
2
- require_relative 'auth_tool/helper'
3
2
  require_relative 'auth_tool/oauth_1'
4
3
  require_relative 'auth_tool/oauth_2'
5
4
 
@@ -7,12 +6,13 @@ module AuthTool
7
6
  ##
8
7
  # Creates a client object for the specified API.
9
8
  #
10
- # @param [String] api_name
11
- # The name of the API/company.
9
+ # @param [String] client_secrets
10
+ # The client_secrets hash for the API
12
11
  #
13
12
  # @return [AuthTool::Client] The client.
14
- def self.get_client api_name
15
- client = create_client(read_config(api_name))
13
+ def self.get_client client_secrets
14
+ raise "Expected Hash, received #{client_secrets.class}" if client_secrets.class != Hash
15
+ client = create_client(client_secrets)
16
16
  return client
17
17
  end
18
18
 
@@ -98,13 +98,4 @@ module AuthTool
98
98
  def self.create_client options
99
99
  AuthTool::Client.new options
100
100
  end
101
-
102
- ##
103
- # Gets config hash for the given API
104
- #
105
- # @param [String] api_name
106
- # The name of the API/Company as it appears in the database
107
- def self.read_config api_name
108
- AuthTool::Helper.read_secrets(api_name)
109
- end
110
101
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: auth_tool
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Fan
@@ -54,13 +54,10 @@ files:
54
54
  - auth_tool.gemspec
55
55
  - bin/console
56
56
  - bin/setup
57
- - client_secrets/README.md
58
- - client_secrets/client_secrets.json
59
57
  - examples/oauth1-twitter.rb
60
58
  - examples/oauth2-github.rb
61
59
  - lib/auth_tool.rb
62
60
  - lib/auth_tool/client.rb
63
- - lib/auth_tool/helper.rb
64
61
  - lib/auth_tool/oauth_1.rb
65
62
  - lib/auth_tool/oauth_2.rb
66
63
  - lib/auth_tool/version.rb
@@ -1,33 +0,0 @@
1
- client_secrets.json
2
- ===
3
-
4
- Format for basic 3-legged OAuth entries:
5
- ---
6
- ```
7
- {
8
- "api_name":{
9
- "temporary_credential_uri": "oauth/request_token",
10
- "authorization_uri": "oauth/authorize",
11
- "token_credential_uri": "oauth/access_token",
12
- "client_credential_key": "key",
13
- "client_credential_secret": "secret",
14
- "callback": "callback",
15
- "verifier": "verifier",
16
- "oauth_version": "version",
17
- "params:"{
18
- "sample_param": "sample"
19
- }
20
- }
21
- ```
22
- Parameters:
23
- ---
24
- - **api_name**: Lowercase name of the API/company.
25
- - **temporary_credential_uri**: Full URL of the request token endpoint.
26
- - **authorization_uri**: URL to redirect the user to so they can authenticate with the service.
27
- - **token_credential_uri**: Full URL of the access token endpoint.
28
- - **client_credential_key**: Client key (ID) provided by the service's API dashboard.
29
- - **client_credential_secret**: Client secret provided by the service's API dashboard.
30
- - **callback**: Securable callback URL (**TODO:** update once we figure out the endpoint).
31
- - **verifier**: Name of the verifier key that the Auth server passes back after the user successfully authenticates with them.
32
- - **oauth_version**: Either 1 or 2 depending on the OAuth implementation of the API.
33
- - **params**: (Optional) Hash of extra parameter values that the API requests.
@@ -1,41 +0,0 @@
1
- {
2
- "twitter":{
3
- "temporary_credential_uri": "https://api.twitter.com/oauth/request_token",
4
- "authorization_uri": "https://api.twitter.com/oauth/authorize",
5
- "token_credential_uri": "https://api.twitter.com/oauth/access_token",
6
- "client_credential_key": "ajkMgzvyhFwZV9hBgQjlW0rrG",
7
- "client_credential_secret": "BKorJt4MRMpGxCGXNWGz0nFBhd7XfRx3vOHQpL24LKImcLlKXU",
8
- "callback": "http://localhost:4567/callback",
9
- "verifier": "oauth_verifier",
10
- "oauth_version": "1"
11
- },
12
- "cacoo":{
13
- "temporary_credential_uri": "https://cacoo.com/oauth/request_token",
14
- "authorization_uri": "https://cacoo.com/oauth/authorize",
15
- "token_credential_uri": "https://cacoo.com/oauth/access_token",
16
- "client_credential_key": "GSObuYmNbvzIRWlDRiHLyI",
17
- "client_credential_secret": "pHCMknNDivnkAeSreVpKZZhNdAasUGGimBmBagSDlj",
18
- "callback": "http://localhost:4567/",
19
- "verifier": "oauth_verifier",
20
- "oauth_version": "1"
21
- },
22
- "google":{
23
- "client_id":"915626980700-ks501tpkrffod16sjvbumikt1q3s5q5m.apps.googleusercontent.com",
24
- "project_id":"atomic-optics-168719",
25
- "authorization_uri":"https://accounts.google.com/o/oauth2/auth",
26
- "token_credential_uri":"https://accounts.google.com/o/oauth2/token",
27
- "auth_provider_x509_cert_url":"https://www.googleapis.com/oauth2/v1/certs",
28
- "client_secret":"N7ceZl5u0mGZ8E-v-2hNj6Iz",
29
- "oauth_version": "2",
30
- "redirect_uri": "http://localhost:4567/",
31
- "scope":"https://www.googleapis.com/auth/adsensehost"},
32
- "github":{
33
- "client_id":"c1d4265302eba1aa4f37",
34
- "authorization_uri":"https://github.com/login/oauth/authorize",
35
- "token_credential_uri":"https://github.com/login/oauth/access_token",
36
- "client_secret":"7be3891166bdfc95193b20bf3e65dbf0844e2121",
37
- "oauth_version": "2",
38
- "redirect_uri": "http://localhost:4567/callback",
39
- "scope": "user"
40
- }
41
- }
@@ -1,33 +0,0 @@
1
- require 'json'
2
- require 'faraday'
3
-
4
- f = File.new('../client_secrets/client_secrets.json', 'r')
5
- Client_secrets = JSON.parse(f.read).freeze
6
-
7
- module AuthTool
8
- module Helper
9
- ##
10
- # Returns the configuration hash for the given API.
11
- #
12
- # @param [String] api_name
13
- # The api you wish to authenticate against (i.e., twitter)
14
- #
15
- # @return [Hash] The configuration hash for api_name
16
- def self.read_secrets api_name
17
- raise "API not found" unless Client_secrets.has_key?(api_name.downcase)
18
- return Client_secrets[api_name.downcase]
19
- end
20
-
21
- ##
22
- # Returns a Faraday Connetion object
23
- #
24
- # @param [Hash] params
25
- # The additional parameters hash.
26
- #
27
- # @return [Faraday::Connection]
28
- def self.get_connection(params)
29
- connection = Faraday.new(:params => params)
30
- return connection
31
- end
32
- end
33
- end