omniauth-gitee 0.0.1

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: e417ac429ac35665584df4030aa90ec4e33286df6fcc367ff6067be8f23a997f
4
+ data.tar.gz: d29dc59a39a9e716b9d6272c496e70a8d371a568fd46a48dbb659e0222475d07
5
+ SHA512:
6
+ metadata.gz: 23cfb2519e8678adade98b1c97c3ce8576fbca1b541e73e8d191f389c3d4a0757bbfc7e5d8328e624e2fc5a4e4094210d0f8de2562403f259df0c0e77d9cbf7f
7
+ data.tar.gz: 8ef217c2300f608c5446e8528e7980b675db317ff5c4ba28ddbfc5fcc3ae8f2c939f3519dfdd2722f44f4cf75c256db96efbf905cc0759de61e542efbbb9c873
@@ -0,0 +1,26 @@
1
+ name: Ruby
2
+
3
+ on:
4
+ push:
5
+ branches: [ master ]
6
+ pull_request:
7
+ branches: [ master ]
8
+
9
+ jobs:
10
+ test:
11
+ runs-on: ubuntu-latest
12
+ strategy:
13
+ matrix:
14
+ ruby-version: ['2.4', '2.5', '2.6', '2.7', '3.0', '3.1', 'truffleruby-head']
15
+
16
+ steps:
17
+ - uses: actions/checkout@v2
18
+ - name: Set up Ruby ${{ matrix.ruby-version }}
19
+ uses: ruby/setup-ruby@v1
20
+ with:
21
+ ruby-version: ${{ matrix.ruby-version }}
22
+ - name: Build and test with Rake
23
+ run: |
24
+ gem install bundler
25
+ bundle install --jobs 4 --retry 3
26
+ bundle exec rake
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ /pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/.idea/.gitignore ADDED
@@ -0,0 +1,8 @@
1
+ # Default ignored files
2
+ /shelf/
3
+ /workspace.xml
4
+ # Editor-based HTTP Client requests
5
+ /httpRequests/
6
+ # Datasource local storage ignored files
7
+ /dataSources/
8
+ /dataSources.local.xml
data/.idea/misc.xml ADDED
@@ -0,0 +1,4 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <project version="4">
3
+ <component name="ProjectRootManager" version="2" project-jdk-name="ruby-2.6.8-p205" project-jdk-type="RUBY_SDK" />
4
+ </project>
data/.idea/modules.xml ADDED
@@ -0,0 +1,8 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <project version="4">
3
+ <component name="ProjectModuleManager">
4
+ <modules>
5
+ <module fileurl="file://$PROJECT_DIR$/.idea/omniauth-gitee.iml" filepath="$PROJECT_DIR$/.idea/omniauth-gitee.iml" />
6
+ </modules>
7
+ </component>
8
+ </project>
@@ -0,0 +1,98 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <module type="RUBY_MODULE" version="4">
3
+ <component name="ModuleRunConfigurationManager">
4
+ <shared />
5
+ </component>
6
+ <component name="NewModuleRootManager">
7
+ <content url="file://$MODULE_DIR$">
8
+ <sourceFolder url="file://$MODULE_DIR$/features" isTestSource="true" />
9
+ <sourceFolder url="file://$MODULE_DIR$/spec" isTestSource="true" />
10
+ <sourceFolder url="file://$MODULE_DIR$/test" isTestSource="true" />
11
+ </content>
12
+ <orderEntry type="jdk" jdkName="rbenv: 3.0.4" jdkType="RUBY_SDK" />
13
+ <orderEntry type="sourceFolder" forTests="false" />
14
+ <orderEntry type="library" scope="PROVIDED" name="addressable (v2.8.0, rbenv: 3.0.4) [gem]" level="application" />
15
+ <orderEntry type="library" scope="PROVIDED" name="bundler (v2.3.17, rbenv: 3.0.4) [gem]" level="application" />
16
+ <orderEntry type="library" scope="PROVIDED" name="coderay (v1.1.3, rbenv: 3.0.4) [gem]" level="application" />
17
+ <orderEntry type="library" scope="PROVIDED" name="crack (v0.4.5, rbenv: 3.0.4) [gem]" level="application" />
18
+ <orderEntry type="library" scope="PROVIDED" name="diff-lcs (v1.5.0, rbenv: 3.0.4) [gem]" level="application" />
19
+ <orderEntry type="library" scope="PROVIDED" name="docile (v1.4.0, rbenv: 3.0.4) [gem]" level="application" />
20
+ <orderEntry type="library" scope="PROVIDED" name="faraday (v2.3.0, rbenv: 3.0.4) [gem]" level="application" />
21
+ <orderEntry type="library" scope="PROVIDED" name="faraday-net_http (v2.0.3, rbenv: 3.0.4) [gem]" level="application" />
22
+ <orderEntry type="library" scope="PROVIDED" name="ffi (v1.15.5, rbenv: 3.0.4) [gem]" level="application" />
23
+ <orderEntry type="library" scope="PROVIDED" name="formatador (v1.1.0, rbenv: 3.0.4) [gem]" level="application" />
24
+ <orderEntry type="library" scope="PROVIDED" name="growl (v1.0.3, rbenv: 3.0.4) [gem]" level="application" />
25
+ <orderEntry type="library" scope="PROVIDED" name="guard (v2.18.0, rbenv: 3.0.4) [gem]" level="application" />
26
+ <orderEntry type="library" scope="PROVIDED" name="guard-bundler (v3.0.0, rbenv: 3.0.4) [gem]" level="application" />
27
+ <orderEntry type="library" scope="PROVIDED" name="guard-compat (v1.2.1, rbenv: 3.0.4) [gem]" level="application" />
28
+ <orderEntry type="library" scope="PROVIDED" name="guard-rspec (v4.7.3, rbenv: 3.0.4) [gem]" level="application" />
29
+ <orderEntry type="library" scope="PROVIDED" name="hashdiff (v1.0.1, rbenv: 3.0.4) [gem]" level="application" />
30
+ <orderEntry type="library" scope="PROVIDED" name="hashie (v5.0.0, rbenv: 3.0.4) [gem]" level="application" />
31
+ <orderEntry type="library" scope="PROVIDED" name="jwt (v2.4.1, rbenv: 3.0.4) [gem]" level="application" />
32
+ <orderEntry type="library" scope="PROVIDED" name="listen (v3.7.1, rbenv: 3.0.4) [gem]" level="application" />
33
+ <orderEntry type="library" scope="PROVIDED" name="lumberjack (v1.2.8, rbenv: 3.0.4) [gem]" level="application" />
34
+ <orderEntry type="library" scope="PROVIDED" name="method_source (v1.0.0, rbenv: 3.0.4) [gem]" level="application" />
35
+ <orderEntry type="library" scope="PROVIDED" name="multi_xml (v0.6.0, rbenv: 3.0.4) [gem]" level="application" />
36
+ <orderEntry type="library" scope="PROVIDED" name="nenv (v0.3.0, rbenv: 3.0.4) [gem]" level="application" />
37
+ <orderEntry type="library" scope="PROVIDED" name="notiffany (v0.1.3, rbenv: 3.0.4) [gem]" level="application" />
38
+ <orderEntry type="library" scope="PROVIDED" name="oauth2 (v2.0.4, rbenv: 3.0.4) [gem]" level="application" />
39
+ <orderEntry type="library" scope="PROVIDED" name="omniauth (v2.1.0, rbenv: 3.0.4) [gem]" level="application" />
40
+ <orderEntry type="library" scope="PROVIDED" name="omniauth-oauth2 (v1.7.3, rbenv: 3.0.4) [gem]" level="application" />
41
+ <orderEntry type="library" scope="PROVIDED" name="pry (v0.14.1, rbenv: 3.0.4) [gem]" level="application" />
42
+ <orderEntry type="library" scope="PROVIDED" name="public_suffix (v4.0.7, rbenv: 3.0.4) [gem]" level="application" />
43
+ <orderEntry type="library" scope="PROVIDED" name="rack (v2.2.4, rbenv: 3.0.4) [gem]" level="application" />
44
+ <orderEntry type="library" scope="PROVIDED" name="rack-protection (v2.2.0, rbenv: 3.0.4) [gem]" level="application" />
45
+ <orderEntry type="library" scope="PROVIDED" name="rack-test (v2.0.2, rbenv: 3.0.4) [gem]" level="application" />
46
+ <orderEntry type="library" scope="PROVIDED" name="rake (v13.0.6, rbenv: 3.0.4) [gem]" level="application" />
47
+ <orderEntry type="library" scope="PROVIDED" name="rash_alt (v0.4.12, rbenv: 3.0.4) [gem]" level="application" />
48
+ <orderEntry type="library" scope="PROVIDED" name="rb-fsevent (v0.11.1, rbenv: 3.0.4) [gem]" level="application" />
49
+ <orderEntry type="library" scope="PROVIDED" name="rb-inotify (v0.10.1, rbenv: 3.0.4) [gem]" level="application" />
50
+ <orderEntry type="library" scope="PROVIDED" name="rexml (v3.2.5, rbenv: 3.0.4) [gem]" level="application" />
51
+ <orderEntry type="library" scope="PROVIDED" name="rspec (v3.11.0, rbenv: 3.0.4) [gem]" level="application" />
52
+ <orderEntry type="library" scope="PROVIDED" name="rspec-core (v3.11.0, rbenv: 3.0.4) [gem]" level="application" />
53
+ <orderEntry type="library" scope="PROVIDED" name="rspec-expectations (v3.11.0, rbenv: 3.0.4) [gem]" level="application" />
54
+ <orderEntry type="library" scope="PROVIDED" name="rspec-mocks (v3.11.1, rbenv: 3.0.4) [gem]" level="application" />
55
+ <orderEntry type="library" scope="PROVIDED" name="rspec-support (v3.11.0, rbenv: 3.0.4) [gem]" level="application" />
56
+ <orderEntry type="library" scope="PROVIDED" name="ruby2_keywords (v0.0.5, rbenv: 3.0.4) [gem]" level="application" />
57
+ <orderEntry type="library" scope="PROVIDED" name="shellany (v0.0.1, rbenv: 3.0.4) [gem]" level="application" />
58
+ <orderEntry type="library" scope="PROVIDED" name="simplecov (v0.21.2, rbenv: 3.0.4) [gem]" level="application" />
59
+ <orderEntry type="library" scope="PROVIDED" name="simplecov-html (v0.12.3, rbenv: 3.0.4) [gem]" level="application" />
60
+ <orderEntry type="library" scope="PROVIDED" name="simplecov_json_formatter (v0.1.4, rbenv: 3.0.4) [gem]" level="application" />
61
+ <orderEntry type="library" scope="PROVIDED" name="thor (v1.2.1, rbenv: 3.0.4) [gem]" level="application" />
62
+ <orderEntry type="library" scope="PROVIDED" name="version_gem (v1.1.0, rbenv: 3.0.4) [gem]" level="application" />
63
+ <orderEntry type="library" scope="PROVIDED" name="webmock (v3.14.0, rbenv: 3.0.4) [gem]" level="application" />
64
+ </component>
65
+ <component name="RakeTasksCache">
66
+ <option name="myRootTask">
67
+ <RakeTaskImpl id="rake">
68
+ <subtasks>
69
+ <RakeTaskImpl description="Build omniauth-github-2.0.0.gem into the pkg directory" fullCommand="build" id="build" />
70
+ <RakeTaskImpl id="build">
71
+ <subtasks>
72
+ <RakeTaskImpl description="Generate SHA512 checksum if omniauth-github-2.0.0.gem into the checksums directory" fullCommand="build:checksum" id="checksum" />
73
+ </subtasks>
74
+ </RakeTaskImpl>
75
+ <RakeTaskImpl description="Remove any temporary products" fullCommand="clean" id="clean" />
76
+ <RakeTaskImpl description="Remove any generated files" fullCommand="clobber" id="clobber" />
77
+ <RakeTaskImpl description="Run specs" fullCommand="default" id="default" />
78
+ <RakeTaskImpl description="Build and install omniauth-github-2.0.0.gem into system gems" fullCommand="install" id="install" />
79
+ <RakeTaskImpl id="install">
80
+ <subtasks>
81
+ <RakeTaskImpl description="Build and install omniauth-github-2.0.0.gem into system gems without network access" fullCommand="install:local" id="local" />
82
+ </subtasks>
83
+ </RakeTaskImpl>
84
+ <RakeTaskImpl description="Create tag v2.0.0 and build and push omniauth-github-2.0.0.gem to rubygems.org" fullCommand="release[remote]" id="release[remote]" />
85
+ <RakeTaskImpl description="Run RSpec code examples" fullCommand="spec" id="spec" />
86
+ <RakeTaskImpl description="" fullCommand="release" id="release" />
87
+ <RakeTaskImpl id="release">
88
+ <subtasks>
89
+ <RakeTaskImpl description="" fullCommand="release:guard_clean" id="guard_clean" />
90
+ <RakeTaskImpl description="" fullCommand="release:rubygem_push" id="rubygem_push" />
91
+ <RakeTaskImpl description="" fullCommand="release:source_control_push" id="source_control_push" />
92
+ </subtasks>
93
+ </RakeTaskImpl>
94
+ </subtasks>
95
+ </RakeTaskImpl>
96
+ </option>
97
+ </component>
98
+ </module>
data/.idea/vcs.xml ADDED
@@ -0,0 +1,6 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <project version="4">
3
+ <component name="VcsDirectoryMappings">
4
+ <mapping directory="$PROJECT_DIR$" vcs="Git" />
5
+ </component>
6
+ </project>
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --colour
data/Gemfile ADDED
@@ -0,0 +1,13 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in omniauth-gitee.gemspec
4
+ gemspec
5
+
6
+ group :development, :test do
7
+ gem 'guard'
8
+ gem 'guard-rspec'
9
+ gem 'guard-bundler'
10
+ gem 'rb-fsevent'
11
+ gem 'growl'
12
+ gem 'rake'
13
+ end
data/Guardfile ADDED
@@ -0,0 +1,10 @@
1
+ guard 'rspec', :version => 2 do
2
+ watch(%r{^spec/.+_spec\.rb$})
3
+ watch(%r{^lib/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
4
+ watch('spec/spec_helper.rb') { "spec" }
5
+ end
6
+
7
+ guard 'bundler' do
8
+ watch('Gemfile')
9
+ watch('omniauth-gitee.gemspec')
10
+ end
data/LICENSE.txt ADDED
@@ -0,0 +1,7 @@
1
+ Copyright (c) 2011 Michael Bleigh and Intridea, Inc.
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4
+
5
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6
+
7
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,81 @@
1
+ # OmniAuth Gitee (码云)
2
+
3
+ Forked from [omniauth-github](https://github.com/omniauth/omniauth-github)
4
+
5
+ TODO: Readme
6
+
7
+ ***
8
+
9
+ ![Ruby](https://github.com/omniauth/omniauth-github/workflows/Ruby/badge.svg?branch=master)
10
+
11
+ # OmniAuth GitHub
12
+
13
+ This is the official OmniAuth strategy for authenticating to GitHub. To
14
+ use it, you'll need to sign up for an OAuth2 Application ID and Secret
15
+ on the [GitHub Applications Page](https://github.com/settings/applications).
16
+
17
+ ## Installation
18
+
19
+ ```ruby
20
+ gem 'omniauth-gitee', github: 'omniauth/omniauth-gitee', branch: 'master'
21
+ ```
22
+
23
+ ## Basic Usage
24
+
25
+ ```ruby
26
+ use OmniAuth::Builder do
27
+ provider :github, ENV['GITHUB_KEY'], ENV['GITHUB_SECRET']
28
+ end
29
+ ```
30
+
31
+
32
+ ## Basic Usage Rails
33
+
34
+ In `config/initializers/github.rb`
35
+
36
+ ```ruby
37
+ Rails.application.config.middleware.use OmniAuth::Builder do
38
+ provider :github, ENV['GITHUB_KEY'], ENV['GITHUB_SECRET']
39
+ end
40
+ ```
41
+
42
+
43
+ ## Github Enterprise Usage
44
+
45
+ ```ruby
46
+ provider :github, ENV['GITHUB_KEY'], ENV['GITHUB_SECRET'],
47
+ {
48
+ :client_options => {
49
+ :site => 'https://github.YOURDOMAIN.com/api/v3',
50
+ :authorize_url => 'https://github.YOURDOMAIN.com/login/oauth/authorize',
51
+ :token_url => 'https://github.YOURDOMAIN.com/login/oauth/access_token',
52
+ }
53
+ }
54
+ ```
55
+
56
+ ## Scopes
57
+
58
+ GitHub API v3 lets you set scopes to provide granular access to different types of data:
59
+
60
+ ```ruby
61
+ use OmniAuth::Builder do
62
+ provider :github, ENV['GITHUB_KEY'], ENV['GITHUB_SECRET'], scope: "user,repo,gist"
63
+ end
64
+ ```
65
+
66
+ More info on [Scopes](https://docs.github.com/en/developers/apps/scopes-for-oauth-apps).
67
+
68
+
69
+ ## Semver
70
+ This project adheres to Semantic Versioning 2.0.0. Any violations of this scheme are considered to be bugs.
71
+ All changes will be tracked [here](https://github.com/omniauth/omniauth-github/releases).
72
+
73
+ ## License
74
+
75
+ Copyright (c) 2011 Michael Bleigh and Intridea, Inc.
76
+
77
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
78
+
79
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
80
+
81
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Rakefile ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
3
+ require 'rspec/core/rake_task'
4
+
5
+ RSpec::Core::RakeTask.new
6
+
7
+ desc 'Run specs'
8
+ task :default => :spec
@@ -0,0 +1,84 @@
1
+ require 'omniauth-oauth2'
2
+
3
+ module OmniAuth
4
+ module Strategies
5
+ class Gitee < OmniAuth::Strategies::OAuth2
6
+ option :client_options, {
7
+ :site => 'https://gitee.com',
8
+ :authorize_url => 'https://gitee.com/oauth/authorize',
9
+ :token_url => 'https://gitee.com/oauth/token'
10
+ }
11
+
12
+ def request_phase
13
+ super
14
+ end
15
+
16
+ def authorize_params
17
+ super.tap do |params|
18
+ %w[scope client_options].each do |v|
19
+ if request.params[v]
20
+ params[v.to_sym] = request.params[v]
21
+ end
22
+ end
23
+ end
24
+ end
25
+
26
+ uid { raw_info['id'].to_s }
27
+
28
+ info do
29
+ {
30
+ 'nickname' => raw_info['login'],
31
+ 'email' => email,
32
+ 'name' => raw_info['name'],
33
+ 'image' => raw_info['avatar_url'],
34
+ 'urls' => {
35
+ 'GitHub' => raw_info['html_url'],
36
+ 'Blog' => raw_info['blog'],
37
+ },
38
+ }
39
+ end
40
+
41
+ extra do
42
+ {:raw_info => raw_info, :all_emails => emails, :scope => scope }
43
+ end
44
+
45
+ def raw_info
46
+ access_token.options[:mode] = :header
47
+ @raw_info ||= access_token.get('user').parsed
48
+ end
49
+
50
+ def email
51
+ (email_access_allowed?) ? primary_email : raw_info['email']
52
+ end
53
+
54
+ def scope
55
+ access_token['scope']
56
+ end
57
+
58
+ def primary_email
59
+ primary = emails.find{ |i| i['primary'] && i['verified'] }
60
+ primary && primary['email'] || nil
61
+ end
62
+
63
+ # The new /user/emails API - http://developer.github.com/v3/users/emails/#future-response
64
+ def emails
65
+ return [] unless email_access_allowed?
66
+ access_token.options[:mode] = :header
67
+ @emails ||= access_token.get('user/emails', :headers => { 'Accept' => 'application/vnd.github.v3' }).parsed
68
+ end
69
+
70
+ def email_access_allowed?
71
+ return false unless options['scope']
72
+ email_scopes = ['user', 'user:email']
73
+ scopes = options['scope'].split(',')
74
+ (scopes & email_scopes).any?
75
+ end
76
+
77
+ def callback_url
78
+ full_host + callback_path
79
+ end
80
+ end
81
+ end
82
+ end
83
+
84
+ OmniAuth.config.add_camelization 'gitee', 'Gitee'
@@ -0,0 +1,5 @@
1
+ module OmniAuth
2
+ module Gitee
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
@@ -0,0 +1,2 @@
1
+ require "omniauth-gitee/version"
2
+ require 'omniauth/strategies/gitee'
@@ -0,0 +1,25 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/omniauth-gitee/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.authors = ["Mashiro"]
6
+ gem.email = ["moezhx@outlook.com"]
7
+ gem.description = %q{Official OmniAuth strategy for Gitee.}
8
+ gem.summary = %q{Official OmniAuth strategy for Gitee.}
9
+ gem.homepage = "https://github.com/mashirozx/omniauth-gitee"
10
+ gem.license = "MIT"
11
+
12
+ gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
13
+ gem.files = `git ls-files`.split("\n")
14
+ gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
15
+ gem.name = "omniauth-gitee"
16
+ gem.require_paths = ["lib"]
17
+ gem.version = OmniAuth::Gitee::VERSION
18
+
19
+ gem.add_dependency 'omniauth', '~> 2.0'
20
+ gem.add_dependency 'omniauth-oauth2', '~> 1.7.1'
21
+ gem.add_development_dependency 'rspec', '~> 3.5'
22
+ gem.add_development_dependency 'rack-test'
23
+ gem.add_development_dependency 'simplecov'
24
+ gem.add_development_dependency 'webmock'
25
+ end
@@ -0,0 +1,154 @@
1
+ require 'spec_helper'
2
+
3
+ describe OmniAuth::Strategies::Gitee do
4
+ let(:access_token) { instance_double('AccessToken', :options => {}, :[] => 'user') }
5
+ let(:parsed_response) { instance_double('ParsedResponse') }
6
+ let(:response) { instance_double('Response', :parsed => parsed_response) }
7
+
8
+ subject do
9
+ OmniAuth::Strategies::Gitee.new({})
10
+ end
11
+
12
+ before(:each) do
13
+ allow(subject).to receive(:access_token).and_return(access_token)
14
+ end
15
+
16
+ context 'client options' do
17
+ it 'should have correct site' do
18
+ expect(subject.options.client_options.site).to eq('https://gitee.com')
19
+ end
20
+
21
+ it 'should have correct authorize url' do
22
+ expect(subject.options.client_options.authorize_url).to eq('https://gitee.com/oauth/authorize')
23
+ end
24
+
25
+ it 'should have correct token url' do
26
+ expect(subject.options.client_options.token_url).to eq('https://gitee.com/oauth/token')
27
+ end
28
+ end
29
+
30
+ context '#email_access_allowed?' do
31
+ it 'should not allow email if scope is nil' do
32
+ expect(subject.options['scope']).to be_nil
33
+ expect(subject).to_not be_email_access_allowed
34
+ end
35
+
36
+ it 'should allow email if scope is user' do
37
+ subject.options['scope'] = 'user'
38
+ expect(subject).to be_email_access_allowed
39
+ end
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'
43
+ expect(subject).to be_email_access_allowed
44
+ end
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
50
+
51
+ it 'should assume email access not allowed if scope is something currently not documented' do
52
+ subject.options['scope'] = 'currently_not_documented'
53
+ expect(subject).to_not be_email_access_allowed
54
+ end
55
+ end
56
+
57
+ context '#email' do
58
+ it 'should return email from raw_info if available' do
59
+ allow(subject).to receive(:raw_info).and_return({ 'email' => 'you@example.com' })
60
+ expect(subject.email).to eq('you@example.com')
61
+ end
62
+
63
+ it 'should return nil if there is no raw_info and email access is not allowed' do
64
+ allow(subject).to receive(:raw_info).and_return({})
65
+ expect(subject.email).to be_nil
66
+ end
67
+
68
+ it 'should not return the primary email if there is no raw_info and email access is allowed' do
69
+ emails = [
70
+ { 'email' => 'secondary@example.com', 'primary' => false },
71
+ { 'email' => 'primary@example.com', 'primary' => true }
72
+ ]
73
+ allow(subject).to receive(:raw_info).and_return({})
74
+ subject.options['scope'] = 'user'
75
+ allow(subject).to receive(:emails).and_return(emails)
76
+ expect(subject.email).to be_nil
77
+ end
78
+
79
+ it 'should not return the first email if there is no raw_info and email access is allowed' do
80
+ emails = [
81
+ { 'email' => 'first@example.com', 'primary' => false },
82
+ { 'email' => 'second@example.com', 'primary' => false }
83
+ ]
84
+ allow(subject).to receive(:raw_info).and_return({})
85
+ subject.options['scope'] = 'user'
86
+ allow(subject).to receive(:emails).and_return(emails)
87
+ expect(subject.email).to be_nil
88
+ end
89
+ end
90
+
91
+ context '#raw_info' do
92
+ it 'should use relative paths' do
93
+ expect(access_token).to receive(:get).with('user').and_return(response)
94
+ expect(subject.raw_info).to eq(parsed_response)
95
+ end
96
+
97
+ it 'should use the header auth mode' do
98
+ expect(access_token).to receive(:get).with('user').and_return(response)
99
+ subject.raw_info
100
+ expect(access_token.options[:mode]).to eq(:header)
101
+ end
102
+ end
103
+
104
+ context '#emails' do
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)
109
+
110
+ subject.options['scope'] = 'user'
111
+ expect(subject.emails).to eq(parsed_response)
112
+ end
113
+
114
+ 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)
118
+
119
+ subject.options['scope'] = 'user'
120
+ subject.emails
121
+ expect(access_token.options[:mode]).to eq(:header)
122
+ end
123
+ end
124
+
125
+ context '#info.email' do
126
+ it 'should use any available email' do
127
+ allow(subject).to receive(:raw_info).and_return({})
128
+ allow(subject).to receive(:email).and_return('you@example.com')
129
+ expect(subject.info['email']).to eq('you@example.com')
130
+ end
131
+ end
132
+
133
+ context '#info.urls' do
134
+ it 'should use html_url from raw_info' do
135
+ 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')
137
+ end
138
+ end
139
+
140
+ context '#extra.scope' do
141
+ it 'returns the scope on the returned access_token' do
142
+ expect(subject.scope).to eq('user')
143
+ end
144
+ end
145
+
146
+ describe '#callback_url' do
147
+ it 'is a combination of host, script name, and callback path' do
148
+ allow(subject).to receive(:full_host).and_return('https://example.com')
149
+ allow(subject).to receive(:script_name).and_return('/sub_uri')
150
+
151
+ expect(subject.callback_url).to eq('https://example.com/sub_uri/auth/gitee/callback')
152
+ end
153
+ end
154
+ end
@@ -0,0 +1,16 @@
1
+ $:.unshift File.expand_path('..', __FILE__)
2
+ $:.unshift File.expand_path('../../lib', __FILE__)
3
+ require 'simplecov'
4
+ SimpleCov.start
5
+ require 'rspec'
6
+ require 'rack/test'
7
+ require 'webmock/rspec'
8
+ require 'omniauth'
9
+ require 'omniauth-gitee'
10
+
11
+ RSpec.configure do |config|
12
+ config.include WebMock::API
13
+ config.include Rack::Test::Methods
14
+ config.extend OmniAuth::Test::StrategyMacros, :type => :strategy
15
+ end
16
+
metadata ADDED
@@ -0,0 +1,148 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: omniauth-gitee
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Mashiro
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2022-07-07 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: omniauth
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '2.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '2.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: omniauth-oauth2
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 1.7.1
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 1.7.1
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.5'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.5'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rack-test
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: simplecov
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: webmock
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ description: Official OmniAuth strategy for Gitee.
98
+ email:
99
+ - moezhx@outlook.com
100
+ executables: []
101
+ extensions: []
102
+ extra_rdoc_files: []
103
+ files:
104
+ - ".github/workflows/ruby.yml"
105
+ - ".gitignore"
106
+ - ".idea/.gitignore"
107
+ - ".idea/misc.xml"
108
+ - ".idea/modules.xml"
109
+ - ".idea/omniauth-gitee.iml"
110
+ - ".idea/vcs.xml"
111
+ - ".rspec"
112
+ - Gemfile
113
+ - Guardfile
114
+ - LICENSE.txt
115
+ - README.md
116
+ - Rakefile
117
+ - lib/omniauth-gitee.rb
118
+ - lib/omniauth-gitee/version.rb
119
+ - lib/omniauth/strategies/gitee.rb
120
+ - omniauth-gitee.gemspec
121
+ - spec/omniauth/strategies/github_spec.rb
122
+ - spec/spec_helper.rb
123
+ homepage: https://github.com/mashirozx/omniauth-gitee
124
+ licenses:
125
+ - MIT
126
+ metadata: {}
127
+ post_install_message:
128
+ rdoc_options: []
129
+ require_paths:
130
+ - lib
131
+ required_ruby_version: !ruby/object:Gem::Requirement
132
+ requirements:
133
+ - - ">="
134
+ - !ruby/object:Gem::Version
135
+ version: '0'
136
+ required_rubygems_version: !ruby/object:Gem::Requirement
137
+ requirements:
138
+ - - ">="
139
+ - !ruby/object:Gem::Version
140
+ version: '0'
141
+ requirements: []
142
+ rubygems_version: 3.2.33
143
+ signing_key:
144
+ specification_version: 4
145
+ summary: Official OmniAuth strategy for Gitee.
146
+ test_files:
147
+ - spec/omniauth/strategies/github_spec.rb
148
+ - spec/spec_helper.rb