omniauth-etencent 0.1.0
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 +7 -0
- data/.github/workflows/main.yml +19 -0
- data/.gitignore +12 -0
- data/.rspec +3 -0
- data/Gemfile +8 -0
- data/Gemfile.lock +73 -0
- data/LICENSE.txt +21 -0
- data/README.md +46 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/omniauth-etencent.rb +4 -0
- data/lib/omniauth-etencent/access_token.rb +15 -0
- data/lib/omniauth-etencent/version.rb +5 -0
- data/lib/omniauth/strategies/etencent.rb +77 -0
- data/omniauth-etencent.gemspec +28 -0
- metadata +88 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 9f048e04baf77bb7597b9b29291993e886d917844bf3af04f82bfa10067180bf
|
4
|
+
data.tar.gz: 26510297e6733032ab0949c36fac2ad5a834ba5fb0ca9810e84744a7edc67ff2
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 8d3e357912de3de231bec567a9a61752207675349ea400aa31aac2ccd2475619987edc52806fef869ae44aa2803370dbfa4a98e50cbf70ac517071c4f59d68dd
|
7
|
+
data.tar.gz: 14534c50851b6d63358802712d9a39cb88147eb2ed97bfb9f019ac37ed441031ac15bc3e9ce9dbe853bf4d14f1e63446edc924ab0f541a1f430ba5e341d695bc
|
@@ -0,0 +1,19 @@
|
|
1
|
+
name: Main
|
2
|
+
on:
|
3
|
+
push:
|
4
|
+
branches:
|
5
|
+
- main
|
6
|
+
tags:
|
7
|
+
- '**'
|
8
|
+
jobs:
|
9
|
+
test:
|
10
|
+
runs-on: ubuntu-latest
|
11
|
+
steps:
|
12
|
+
- uses: actions/checkout@master
|
13
|
+
- name: Set up Ruby
|
14
|
+
uses: ruby/setup-ruby@v1
|
15
|
+
with:
|
16
|
+
ruby-version: 2.6
|
17
|
+
bundler-cache: true
|
18
|
+
- name: Run tests
|
19
|
+
run: bundle exec rspec
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,73 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
omniauth-etencent (0.1.0)
|
5
|
+
omniauth (~> 2.0)
|
6
|
+
omniauth-oauth2 (~> 1.7.1)
|
7
|
+
|
8
|
+
GEM
|
9
|
+
remote: https://rubygems.org/
|
10
|
+
specs:
|
11
|
+
byebug (11.1.3)
|
12
|
+
diff-lcs (1.4.4)
|
13
|
+
faraday (1.4.2)
|
14
|
+
faraday-em_http (~> 1.0)
|
15
|
+
faraday-em_synchrony (~> 1.0)
|
16
|
+
faraday-excon (~> 1.1)
|
17
|
+
faraday-net_http (~> 1.0)
|
18
|
+
faraday-net_http_persistent (~> 1.1)
|
19
|
+
multipart-post (>= 1.2, < 3)
|
20
|
+
ruby2_keywords (>= 0.0.4)
|
21
|
+
faraday-em_http (1.0.0)
|
22
|
+
faraday-em_synchrony (1.0.0)
|
23
|
+
faraday-excon (1.1.0)
|
24
|
+
faraday-net_http (1.0.1)
|
25
|
+
faraday-net_http_persistent (1.1.0)
|
26
|
+
hashie (4.1.0)
|
27
|
+
jwt (2.2.3)
|
28
|
+
multi_json (1.15.0)
|
29
|
+
multi_xml (0.6.0)
|
30
|
+
multipart-post (2.1.1)
|
31
|
+
oauth2 (1.4.7)
|
32
|
+
faraday (>= 0.8, < 2.0)
|
33
|
+
jwt (>= 1.0, < 3.0)
|
34
|
+
multi_json (~> 1.3)
|
35
|
+
multi_xml (~> 0.5)
|
36
|
+
rack (>= 1.2, < 3)
|
37
|
+
omniauth (2.0.4)
|
38
|
+
hashie (>= 3.4.6)
|
39
|
+
rack (>= 1.6.2, < 3)
|
40
|
+
rack-protection
|
41
|
+
omniauth-oauth2 (1.7.1)
|
42
|
+
oauth2 (~> 1.4)
|
43
|
+
omniauth (>= 1.9, < 3)
|
44
|
+
rack (2.2.3)
|
45
|
+
rack-protection (2.1.0)
|
46
|
+
rack
|
47
|
+
rake (12.3.3)
|
48
|
+
rspec (3.10.0)
|
49
|
+
rspec-core (~> 3.10.0)
|
50
|
+
rspec-expectations (~> 3.10.0)
|
51
|
+
rspec-mocks (~> 3.10.0)
|
52
|
+
rspec-core (3.10.1)
|
53
|
+
rspec-support (~> 3.10.0)
|
54
|
+
rspec-expectations (3.10.1)
|
55
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
56
|
+
rspec-support (~> 3.10.0)
|
57
|
+
rspec-mocks (3.10.2)
|
58
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
59
|
+
rspec-support (~> 3.10.0)
|
60
|
+
rspec-support (3.10.2)
|
61
|
+
ruby2_keywords (0.0.4)
|
62
|
+
|
63
|
+
PLATFORMS
|
64
|
+
ruby
|
65
|
+
|
66
|
+
DEPENDENCIES
|
67
|
+
byebug
|
68
|
+
omniauth-etencent!
|
69
|
+
rake (~> 12.0)
|
70
|
+
rspec (~> 3.0)
|
71
|
+
|
72
|
+
BUNDLED WITH
|
73
|
+
2.1.4
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2021 jimcheung
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
[](https://badge.fury.io/rb/omniauth-etencent)
|
2
|
+
[](https://github.com/jinhucheung/omniauth-etencent/actions)
|
3
|
+
|
4
|
+
# Omniauth Etencent
|
5
|
+
|
6
|
+
This is the official OmniAuth strategy for authenticating to Tencent Marketing. To use it, you'll need to sign up for an OAuth2 Application ID and Secret on the [Tencent Marketing Applications Page](https://developers.e.qq.com/app).
|
7
|
+
|
8
|
+
## Installation
|
9
|
+
|
10
|
+
Add this line to your application's Gemfile:
|
11
|
+
|
12
|
+
```ruby
|
13
|
+
gem 'omniauth-etencent'
|
14
|
+
```
|
15
|
+
|
16
|
+
And then execute:
|
17
|
+
|
18
|
+
```
|
19
|
+
$ bundle install
|
20
|
+
```
|
21
|
+
|
22
|
+
Or install it yourself as:
|
23
|
+
|
24
|
+
```
|
25
|
+
$ gem install omniauth-etencent
|
26
|
+
```
|
27
|
+
|
28
|
+
## Usage
|
29
|
+
|
30
|
+
`OmniAuth::Strategies::Etencent` is simply a Rack middleware. Read the OmniAuth docs for detailed instructions: https://github.com/intridea/omniauth.
|
31
|
+
|
32
|
+
Here's a quick example, adding the middleware to a Rails app in `config/initializers/omniauth.rb`:
|
33
|
+
|
34
|
+
```ruby
|
35
|
+
Rails.application.config.middleware.use OmniAuth::Builder do
|
36
|
+
provider :etencent, ENV['ETENCENT_APP_ID'], ENV['ETENCENT_APP_SECRET']
|
37
|
+
end
|
38
|
+
```
|
39
|
+
|
40
|
+
## Contributing
|
41
|
+
|
42
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/jinhucheung/omniauth-etencent.
|
43
|
+
|
44
|
+
## License
|
45
|
+
|
46
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "omniauth/etencent"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
module OmniAuth
|
2
|
+
module Etencent
|
3
|
+
class AccessToken < ::OAuth2::AccessToken
|
4
|
+
class << self
|
5
|
+
def from_hash(client, hash)
|
6
|
+
return unless hash && hash['code'] == 0 && hash.dig('data', 'access_token')
|
7
|
+
|
8
|
+
data = hash['data'].merge('expires_in' => hash.dig('data', 'access_token_expires_in'))
|
9
|
+
data['refresh_token_expires_at'] ||= Time.now.to_i + data['refresh_token_expires_in'].to_i if data['refresh_token_expires_in'].to_i > 0
|
10
|
+
super(client, data)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,77 @@
|
|
1
|
+
module OmniAuth
|
2
|
+
module Strategies
|
3
|
+
class Etencent < OmniAuth::Strategies::OAuth2
|
4
|
+
option :name, 'etencent'
|
5
|
+
|
6
|
+
option :client_options, {
|
7
|
+
site: 'https://developers.e.qq.com',
|
8
|
+
authorize_url: '/oauth/authorize',
|
9
|
+
token_url: '/oauth/token',
|
10
|
+
token_method: :get,
|
11
|
+
extract_access_token: ::OmniAuth::Etencent::AccessToken
|
12
|
+
}
|
13
|
+
|
14
|
+
option :authorize_options, %i[scope state account_type account_display_number]
|
15
|
+
|
16
|
+
option :sandbox, false
|
17
|
+
|
18
|
+
def authorize_params
|
19
|
+
super.tap do |params|
|
20
|
+
%w[scope client_options].each do |v|
|
21
|
+
if request.params[v]
|
22
|
+
params[v.to_sym] = request.params[v]
|
23
|
+
# to support omniauth-oauth2's auto csrf protection
|
24
|
+
session['omniauth.state'] = params[:state] if v == 'state'
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
uid { authorizer_info['account_id'] }
|
31
|
+
|
32
|
+
info do
|
33
|
+
authorizer_info
|
34
|
+
end
|
35
|
+
|
36
|
+
credentials do
|
37
|
+
hash = {'token' => access_token.token}
|
38
|
+
hash['refresh_token'] = access_token.refresh_token if access_token.expires? && access_token.refresh_token
|
39
|
+
hash['expires_at'] = access_token.expires_at if access_token.expires?
|
40
|
+
hash['expires'] = access_token.expires?
|
41
|
+
hash['refresh_token_expires_at'] = access_token['refresh_token_expires_at'] if access_token['refresh_token_expires_at']
|
42
|
+
hash
|
43
|
+
end
|
44
|
+
|
45
|
+
extra do
|
46
|
+
{
|
47
|
+
scope: scope
|
48
|
+
}
|
49
|
+
end
|
50
|
+
|
51
|
+
def authorizer_info
|
52
|
+
@authorizer_info ||= access_token.to_hash.dig('authorizer_info') || {}
|
53
|
+
end
|
54
|
+
|
55
|
+
def scope
|
56
|
+
authorizer_info['scope_list']
|
57
|
+
end
|
58
|
+
|
59
|
+
protected
|
60
|
+
|
61
|
+
def client
|
62
|
+
::OAuth2::Client.new(options.client_id, options.client_secret, deep_symbolize(client_options))
|
63
|
+
end
|
64
|
+
|
65
|
+
def client_options
|
66
|
+
options.client_options[:token_url] = "#{api_base_url}#{options.client_options[:token_url]}" if options.client_options[:token_url] !~ /https?:\/\//
|
67
|
+
options.client_options
|
68
|
+
end
|
69
|
+
|
70
|
+
def api_base_url
|
71
|
+
options.sandbox ? 'https://sandbox-api.e.qq.com' : 'https://api.e.qq.com'
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
OmniAuth.config.add_camelization 'etencent', 'Etencent'
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require_relative 'lib/omniauth-etencent/version'
|
2
|
+
|
3
|
+
Gem::Specification.new do |spec|
|
4
|
+
spec.name = "omniauth-etencent"
|
5
|
+
spec.version = OmniAuth::Etencent::VERSION
|
6
|
+
spec.authors = ["jimcheung"]
|
7
|
+
spec.email = ["hi.jinhu.zhang@gmail.com"]
|
8
|
+
|
9
|
+
spec.summary = %q{Omniauth strategy for Tencent Marketing}
|
10
|
+
spec.description = %q{Wrapper the Tencent Marketing Oauth2 API}
|
11
|
+
spec.homepage = "https://github.com/jinhucheung/omniauth-etencent"
|
12
|
+
spec.license = "MIT"
|
13
|
+
|
14
|
+
spec.metadata["homepage_uri"] = spec.homepage
|
15
|
+
spec.metadata["source_code_uri"] = "https://github.com/jinhucheung/omniauth-etencent"
|
16
|
+
|
17
|
+
# Specify which files should be added to the gem when it is released.
|
18
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
19
|
+
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
20
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
21
|
+
end
|
22
|
+
spec.bindir = "exe"
|
23
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
24
|
+
spec.require_paths = ["lib"]
|
25
|
+
|
26
|
+
spec.add_dependency 'omniauth', '~> 2.0'
|
27
|
+
spec.add_dependency 'omniauth-oauth2', '~> 1.7.1'
|
28
|
+
end
|
metadata
ADDED
@@ -0,0 +1,88 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: omniauth-etencent
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- jimcheung
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2021-06-27 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
|
+
description: Wrapper the Tencent Marketing Oauth2 API
|
42
|
+
email:
|
43
|
+
- hi.jinhu.zhang@gmail.com
|
44
|
+
executables: []
|
45
|
+
extensions: []
|
46
|
+
extra_rdoc_files: []
|
47
|
+
files:
|
48
|
+
- ".github/workflows/main.yml"
|
49
|
+
- ".gitignore"
|
50
|
+
- ".rspec"
|
51
|
+
- Gemfile
|
52
|
+
- Gemfile.lock
|
53
|
+
- LICENSE.txt
|
54
|
+
- README.md
|
55
|
+
- Rakefile
|
56
|
+
- bin/console
|
57
|
+
- bin/setup
|
58
|
+
- lib/omniauth-etencent.rb
|
59
|
+
- lib/omniauth-etencent/access_token.rb
|
60
|
+
- lib/omniauth-etencent/version.rb
|
61
|
+
- lib/omniauth/strategies/etencent.rb
|
62
|
+
- omniauth-etencent.gemspec
|
63
|
+
homepage: https://github.com/jinhucheung/omniauth-etencent
|
64
|
+
licenses:
|
65
|
+
- MIT
|
66
|
+
metadata:
|
67
|
+
homepage_uri: https://github.com/jinhucheung/omniauth-etencent
|
68
|
+
source_code_uri: https://github.com/jinhucheung/omniauth-etencent
|
69
|
+
post_install_message:
|
70
|
+
rdoc_options: []
|
71
|
+
require_paths:
|
72
|
+
- lib
|
73
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
74
|
+
requirements:
|
75
|
+
- - ">="
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
78
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
requirements: []
|
84
|
+
rubygems_version: 3.0.8
|
85
|
+
signing_key:
|
86
|
+
specification_version: 4
|
87
|
+
summary: Omniauth strategy for Tencent Marketing
|
88
|
+
test_files: []
|