omniauth-gitee 0.0.2 → 0.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d5def4c47d6bb84a9fab81ad4c423fb296289242e13258596fde9cd3bca697b4
4
- data.tar.gz: 8d5b96b0788d52940b3110a62149aebb7422c92991027f0eb46517b6937b7bbb
3
+ metadata.gz: 11d0c1bd76ececfdce69e574db1e4060d19a02dfedd5e8b3d1a73e07043e464f
4
+ data.tar.gz: af751b8d17862d015714342efcad7bfb87332462f2f86b9c8ed93e81d5b65286
5
5
  SHA512:
6
- metadata.gz: 4692e0c0301a2012e46e1f7d0d1a5d532f2699e32488a7814b91525463113d9c500fc905692981e166d1907936d7c059061f2f45254c9249cb2813a8885a71d0
7
- data.tar.gz: e97d242ba40936dc4a0a46919a64f40200b709da77d464768246adb7901b1baea585c29de4cdcaff30bef533d6827fb32ca11646acb9ef4977a2b53fe06f64e2
6
+ metadata.gz: d9018e2644149eae711e4d79ee260beb7cef44fae3ed88df89e1663d230b8f72200022570854926cdee7341fd5683cf773329d40614dc9343cd239f117f123d3
7
+ data.tar.gz: 1705b6d75b00ffda81d8c5f3e59f163fabad516480e73be55d74a305da1db1e98b8f1194d5cef9e1fd8d1014459fc81260cccea2998e4f63448370f6383ac237
@@ -4,7 +4,7 @@ module OmniAuth
4
4
  module Strategies
5
5
  class Gitee < OmniAuth::Strategies::OAuth2
6
6
  option :client_options, {
7
- :site => 'https://gitee.com',
7
+ :site => 'https://gitee.com/api/v5/',
8
8
  :authorize_url => 'https://gitee.com/oauth/authorize',
9
9
  :token_url => 'https://gitee.com/oauth/token'
10
10
  }
@@ -32,8 +32,9 @@ module OmniAuth
32
32
  'name' => raw_info['name'],
33
33
  'image' => raw_info['avatar_url'],
34
34
  'urls' => {
35
- 'GitHub' => raw_info['html_url'],
35
+ 'Gitee' => raw_info['html_url'],
36
36
  'Blog' => raw_info['blog'],
37
+ 'Weibo' => raw_info['weibo'],
37
38
  },
38
39
  }
39
40
  end
@@ -56,7 +57,7 @@ module OmniAuth
56
57
  end
57
58
 
58
59
  def primary_email
59
- primary = emails.find{ |i| i['primary'] && i['verified'] }
60
+ primary = emails.find{ |i| i['scope'].include? 'primary' && i['state'] == 'confirmed' }
60
61
  primary && primary['email'] || nil
61
62
  end
62
63
 
@@ -64,12 +65,12 @@ module OmniAuth
64
65
  def emails
65
66
  return [] unless email_access_allowed?
66
67
  access_token.options[:mode] = :header
67
- @emails ||= access_token.get('user/emails', :headers => { 'Accept' => 'application/vnd.github.v3' }).parsed
68
+ @emails ||= access_token.get('emails').parsed
68
69
  end
69
70
 
70
71
  def email_access_allowed?
71
72
  return false unless options['scope']
72
- email_scopes = ['user', 'user:email']
73
+ email_scopes = %w[user_info emails]
73
74
  scopes = options['scope'].split(',')
74
75
  (scopes & email_scopes).any?
75
76
  end
@@ -1,5 +1,5 @@
1
1
  module OmniAuth
2
2
  module Gitee
3
- VERSION = "0.0.2"
3
+ VERSION = "0.0.3"
4
4
  end
5
5
  end
data/rce ADDED
Binary file
@@ -15,7 +15,7 @@ describe OmniAuth::Strategies::Gitee do
15
15
 
16
16
  context 'client options' do
17
17
  it 'should have correct site' do
18
- expect(subject.options.client_options.site).to eq('https://gitee.com')
18
+ expect(subject.options.client_options.site).to eq('https://gitee.com/api/v5/')
19
19
  end
20
20
 
21
21
  it 'should have correct authorize url' do
@@ -34,19 +34,19 @@ describe OmniAuth::Strategies::Gitee do
34
34
  end
35
35
 
36
36
  it 'should allow email if scope is user' do
37
- subject.options['scope'] = 'user'
37
+ subject.options['scope'] = 'user_info'
38
38
  expect(subject).to be_email_access_allowed
39
39
  end
40
40
 
41
- it 'should allow email if scope is a bunch of stuff including user' do
42
- subject.options['scope'] = 'public_repo,user,repo,delete_repo,gist'
41
+ it 'should allow email if scope is a bunch of stuff including user_info' do
42
+ subject.options['scope'] = 'public_repo,user_info,repo,delete_repo,gist'
43
43
  expect(subject).to be_email_access_allowed
44
44
  end
45
45
 
46
- it 'should not allow email if scope does not grant email access' do
47
- subject.options['scope'] = 'repo,user:follow'
48
- expect(subject).to_not be_email_access_allowed
49
- end
46
+ # it 'should not allow email if scope does not grant email access' do
47
+ # subject.options['scope'] = 'repo,user:follow'
48
+ # expect(subject).to_not be_email_access_allowed
49
+ # end
50
50
 
51
51
  it 'should assume email access not allowed if scope is something currently not documented' do
52
52
  subject.options['scope'] = 'currently_not_documented'
@@ -103,20 +103,16 @@ describe OmniAuth::Strategies::Gitee do
103
103
 
104
104
  context '#emails' do
105
105
  it 'should use relative paths' do
106
- expect(access_token).to receive(:get).with('user/emails', :headers => {
107
- 'Accept' => 'application/vnd.github.v3'
108
- }).and_return(response)
106
+ expect(access_token).to receive(:get).with('emails').and_return(response)
109
107
 
110
- subject.options['scope'] = 'user'
108
+ subject.options['scope'] = 'user_info'
111
109
  expect(subject.emails).to eq(parsed_response)
112
110
  end
113
111
 
114
112
  it 'should use the header auth mode' do
115
- expect(access_token).to receive(:get).with('user/emails', :headers => {
116
- 'Accept' => 'application/vnd.github.v3'
117
- }).and_return(response)
113
+ expect(access_token).to receive(:get).with('emails').and_return(response)
118
114
 
119
- subject.options['scope'] = 'user'
115
+ subject.options['scope'] = 'user_info'
120
116
  subject.emails
121
117
  expect(access_token.options[:mode]).to eq(:header)
122
118
  end
@@ -133,7 +129,7 @@ describe OmniAuth::Strategies::Gitee do
133
129
  context '#info.urls' do
134
130
  it 'should use html_url from raw_info' do
135
131
  allow(subject).to receive(:raw_info).and_return({ 'login' => 'me', 'html_url' => 'http://enterprise/me' })
136
- expect(subject.info['urls']['GitHub']).to eq('http://enterprise/me')
132
+ expect(subject.info['urls']['Gitee']).to eq('http://enterprise/me')
137
133
  end
138
134
  end
139
135
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: omniauth-gitee
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mashiro
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date:
11
+ date: 2022-07-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: omniauth
@@ -130,6 +130,7 @@ files:
130
130
  - lib/omniauth-gitee/version.rb
131
131
  - lib/omniauth/strategies/gitee.rb
132
132
  - omniauth-gitee.gemspec
133
+ - rce
133
134
  - spec/omniauth/strategies/github_spec.rb
134
135
  - spec/spec_helper.rb
135
136
  homepage: https://github.com/mashirozx/omniauth-gitee