authinator 0.1.0 → 0.2.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: 5bab186640c9c1e8c020d88808cea1d05389e743
4
- data.tar.gz: fd3636d7972b4bda346d1c9b641d633f2e655053
3
+ metadata.gz: acaccc767c48cd514add3e18e616718f04d3a023
4
+ data.tar.gz: d3309ca0fb8b6d79ba307894cc4c05ddf866a3e7
5
5
  SHA512:
6
- metadata.gz: 84848419144e543347fac7faa7fe32e13b10da1ea8e282a9c32f0977dfad44e161313c310dd3114b85c65667d5764bf9c569fd843448074c67cf7635c1d55cb5
7
- data.tar.gz: db8e6561e4032b1b6f7f71648d1f48219ff2b94d260a55fae5f0f237997a7d746904fe5a27e95de0ed9f5846ac60b37444d5763ff3f2d85b1baace23c608826d
6
+ metadata.gz: 57960a2ddfffe2722a030f19dbac1f1a70f069f70587572a5b1147342a8be3a83e370449143335680db888859a8012a26eeede6263c8b0a3b015c666b2cd1104
7
+ data.tar.gz: 0a42070c92fac997b6aac313a0149e598aaea4486596634b959111382ff267805d546739a102054fbc5fabb36f85c804f646118c7a14b74dd45b219f6aaf1089
@@ -23,15 +23,16 @@ module Authinator
23
23
  @provider.site + @provider.token_url
24
24
  end
25
25
 
26
- def exchange(auth_code)
26
+ def exchange(auth_code, redirect_uri)
27
27
  # auth_code = params[:code]
28
- return if auth_code.nil? || auth_code.empty?
28
+ fail 'Cannot Exchange Auth Code (auth_code missing)' if auth_code.nil? || auth_code.empty?
29
+ fail 'Cannot Exchange Auth Code (redirect_uri missing)' if redirect_uri.nil? || redirect_uri.empty?
29
30
 
30
31
  case @provider.name
31
32
  when :google
32
- exchange_with_google(auth_code)
33
+ exchange_with_google(auth_code, redirect_uri)
33
34
  when :stub
34
- exchange_with_stub(auth_code)
35
+ exchange_with_stub(auth_code, redirect_uri)
35
36
  end
36
37
  end
37
38
 
@@ -43,10 +44,10 @@ module Authinator
43
44
  # @provider_hash[:client_secret] = client_options.delete(:client_secret) if client_options[:client_secret]
44
45
  # end
45
46
 
46
- def exchange_with_google(code)
47
+ def exchange_with_google(code, redirect_uri)
47
48
  @client = OAuth2::Client.new(@provider.client_id, @provider.client_secret, @provider.to_hash)
48
49
 
49
- token = @client.auth_code.get_token(code, redirect_uri: 'http://localhost:4200')
50
+ token = @client.auth_code.get_token(code, redirect_uri: redirect_uri)
50
51
 
51
52
  # response = token.get('/api/resource', :params => { 'query_foo' => 'bar' })
52
53
  # response.class.name
@@ -55,7 +56,7 @@ module Authinator
55
56
  token
56
57
  end
57
58
 
58
- def exchange_with_stub(_code)
59
+ def exchange_with_stub(_code, _redirect_uri)
59
60
  @client = OAuth2::Client.new(
60
61
  @provider.client_id,
61
62
  @provider.client_secret,
@@ -24,6 +24,7 @@ module Authinator
24
24
  @provider = Authinator.configuration.provider_for(provider_name)
25
25
 
26
26
  @auth_code = (options.delete :auth_code if options[:auth_code]) || @params['code']
27
+ @redirect_uri = (options.delete :redirect_uri if options[:redirect_uri]) || @params['redirect_uri']
27
28
  @app_name = (options.delete :app_name if options[:app_name]) || application_name
28
29
  @valid_applications = (options.delete :valid_applications if options[:valid_applications]) || Authinator.configuration.valid_applications
29
30
  end
@@ -54,7 +55,7 @@ module Authinator
54
55
  def handle(options = {})
55
56
  application = Doorkeeper::Application.where(name: @app_name)
56
57
  token_issuer = AuthCodeExchanger.new @provider
57
- provider_access_token = token_issuer.exchange @auth_code
58
+ provider_access_token = token_issuer.exchange @auth_code, @redirect_uri
58
59
 
59
60
  begin
60
61
  info = load_info(provider_access_token)
@@ -72,6 +73,7 @@ module Authinator
72
73
  resource_owner_id: user.id,
73
74
  expires_in: expires_in,
74
75
  use_refresh_token: true,
76
+ scopes: :user,
75
77
  )
76
78
 
77
79
  token_data = {
@@ -1,3 +1,3 @@
1
1
  module Authinator
2
- VERSION = '0.1.0'
2
+ VERSION = '0.2.0'
3
3
  end
@@ -19,12 +19,12 @@ describe Authinator::AuthCodeExchanger do
19
19
  client_secret: 'cl_sec',
20
20
  code: '4/code',
21
21
  grant_type: 'authorization_code',
22
+ redirect_uri: 'http://localhost:4200',
22
23
  }
23
24
 
24
25
  @req_headers = {
25
26
  accept: '*/*',
26
27
  content_type: 'application/x-www-form-urlencoded',
27
- user_agent: 'Faraday v0.9.0',
28
28
  }
29
29
 
30
30
  @req_response = {
@@ -60,7 +60,7 @@ describe Authinator::AuthCodeExchanger do
60
60
  headers: @req_headers).
61
61
  to_return(@req_response)
62
62
 
63
- result = ace.exchange(@test_env[:code])
63
+ result = ace.exchange(@test_env[:code], @test_env[:redirect_uri])
64
64
 
65
65
  expect(result.token).to eq @token_hash[:access_token]
66
66
  expect(result.refresh_token).to eq @token_hash[:refresh_token]
@@ -78,7 +78,7 @@ describe Authinator::AuthCodeExchanger do
78
78
  headers: @req_headers).
79
79
  to_return(@req_response)
80
80
 
81
- expect(ace.exchange(@test_env[:code])).to be_a klass
81
+ expect(ace.exchange(@test_env[:code], @test_env[:redirect_uri])).to be_a klass
82
82
  end
83
83
  end
84
84
 
@@ -89,7 +89,7 @@ describe Authinator::AuthCodeExchanger do
89
89
  headers: @req_headers).
90
90
  to_return(@req_response)
91
91
 
92
- result = ace.exchange(@test_env[:code])
92
+ result = ace.exchange(@test_env[:code], @test_env[:redirect_uri])
93
93
 
94
94
  expect(result.token).to eq @token_hash[:access_token]
95
95
  expect(result.refresh_token).to eq @token_hash[:refresh_token]
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: authinator
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alexander Bradner
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-01-14 00:00:00.000000000 Z
11
+ date: 2015-02-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: oauth2