omniauth-ekuaishou 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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 843966ec9516a983699d334a36915021457e21bb39829ef1073dd990c9008742
4
+ data.tar.gz: a087780d3564137e167e07bdc5acb74a8c5196affd7b1ba0d59868f3dbdeb90f
5
+ SHA512:
6
+ metadata.gz: 1ee25f17a8edf0dad9948ad28427fe578ebca8a08bdc3398ef58ed035fdcd5153a69b9cb8c24dd9cc24eda04d624ba6e3a90ab188b751762f1a4ddddf6ebcf2a
7
+ data.tar.gz: 8b0872f8f400d0718924cadc3411c5b9542b9895496cf809b2e0fea81a9c44360bab2d40395dda19977497cd1ca6c9d72353ac33e7ea98ea62b617f0f1ab3b91
@@ -0,0 +1,19 @@
1
+ name: Main
2
+ on:
3
+ push:
4
+ branches:
5
+ - master
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
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/Gemfile ADDED
@@ -0,0 +1,8 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in omniauth-ekuaishou.gemspec
4
+ gemspec
5
+
6
+ gem "rake", "~> 12.0"
7
+ gem "rspec", "~> 3.0"
8
+ gem "byebug"
data/Gemfile.lock ADDED
@@ -0,0 +1,73 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ omniauth-ekuaishou (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-ekuaishou!
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
+ [![Gem Version](https://badge.fury.io/rb/omniauth-ekuaishou.svg)](https://badge.fury.io/rb/omniauth-ekuaishou)
2
+ [![Build Status](https://github.com/jinhucheung/omniauth-ekuaishou/actions/workflows/main.yml/badge.svg)](https:/github.com/jinhucheung/omniauth-ekuaishou/actions)
3
+
4
+ # Omniauth Ekuaishou
5
+
6
+ This is the official OmniAuth strategy for authenticating to Kuaishou Marketing. To use it, you'll need to sign up for an OAuth2 Application ID and Secret on the [Kuaishou Marketing Applications Page](https://developers.e.kuaishou.com/application).
7
+
8
+ ## Installation
9
+
10
+ Add this line to your application's Gemfile:
11
+
12
+ ```ruby
13
+ gem 'omniauth-ekuaishou'
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-ekuaishou
26
+ ```
27
+
28
+ ## Usage
29
+
30
+ `OmniAuth::Strategies::Ekuaishou` 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 :ekuaishou, ENV['EKUAISHOU_APP_ID'], ENV['EKUAISHOU_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-ekuaishou.
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
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "omniauth/ekuaishou"
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,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,5 @@
1
+ require 'json'
2
+ require 'omniauth-oauth2'
3
+ require 'omniauth-ekuaishou/version'
4
+ require 'omniauth-ekuaishou/access_token'
5
+ require 'omniauth/strategies/ekuaishou'
@@ -0,0 +1,15 @@
1
+ module OmniAuth
2
+ module Ekuaishou
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').present?
7
+ data = hash['data']
8
+ super(client, data.merge(
9
+ 'expires_in' => data['access_token_expires_in']
10
+ ))
11
+ end
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,5 @@
1
+ module OmniAuth
2
+ module Ekuaishou
3
+ VERSION = "0.1.0"
4
+ end
5
+ end
@@ -0,0 +1,104 @@
1
+ module OmniAuth
2
+ module Strategies
3
+ class Ekuaishou < OmniAuth::Strategies::OAuth2
4
+ option :name, 'ekuaishou'
5
+
6
+ option :client_options, {
7
+ site: 'https://ad.e.kuaishou.com',
8
+ authorize_url: '/openapi/oauth',
9
+ token_url: '/rest/openapi/oauth2/authorize/access_token',
10
+ extract_access_token: ::OmniAuth::Ekuaishou::AccessToken
11
+ }
12
+
13
+ option :authorize_options, %i[app_id scope state]
14
+
15
+ def authorize_params
16
+ super.tap do |params|
17
+ params[:app_id] = options.client_id if params[:app_id].blank?
18
+
19
+ if params[:scope].present?
20
+ scope = params[:scope]
21
+ scope = JSON.parse(params[:scope]) && params[:scope] rescue params[:scope].split(',') if scope.is_a?(String)
22
+ params[:scope] = scope.is_a?(Array) ? scope.to_json : scope
23
+ end
24
+
25
+ %w[scope client_options].each do |v|
26
+ if request.params[v]
27
+ params[v.to_sym] = request.params[v]
28
+ # to support omniauth-oauth2's auto csrf protection
29
+ session['omniauth.state'] = params[:state] if v == 'state'
30
+ end
31
+ end
32
+ end
33
+ end
34
+
35
+ uid { access_token['advertiser_id'] }
36
+
37
+ info do
38
+ access_token.to_hash.slice('advertiser_id', 'advertiser_ids').merge(raw_info.slice(
39
+ 'user_id',
40
+ 'user_name',
41
+ 'corporation_name',
42
+ 'industry_id',
43
+ 'industry_name',
44
+ 'primary_industry_id',
45
+ 'primary_industry_name'
46
+ ))
47
+ end
48
+
49
+ extra do
50
+ {
51
+ scope: scope,
52
+ raw_info: raw_info,
53
+ refresh_token_expires_in: access_token['refresh_token_expires_in']
54
+ }
55
+ end
56
+
57
+ def raw_info
58
+ @raw_info ||= begin
59
+ resp = client.request(:get, "#{options.client_options[:site]}/rest/openapi/v1/advertiser/info", headers: headers, body: access_token.to_hash.slice('advertiser_id'))
60
+ JSON.parse(resp.body)['data'] rescue {}
61
+ end
62
+ end
63
+
64
+ def scope
65
+ access_token['scope']
66
+ end
67
+
68
+ protected
69
+
70
+ def client
71
+ _client = super
72
+ _client.define_singleton_method(:request) do |verb, url, opts|
73
+ super(verb, url, opts) do |req|
74
+ req.body = req.body.to_json if req.body.is_a?(Hash)
75
+ end
76
+ end
77
+ _client
78
+ end
79
+
80
+ def build_access_token
81
+ request.params['code'] = request.params['auth_code']
82
+ super
83
+ end
84
+
85
+ def token_params
86
+ super.merge(
87
+ 'app_id' => client.id,
88
+ 'secret' => client.secret,
89
+ 'auth_code' => request.params['auth_code'],
90
+ 'parse' => :json,
91
+ 'headers' => headers
92
+ )
93
+ end
94
+
95
+ def headers
96
+ result = { 'Content-Type' => 'application/json' }
97
+ result['Access-Token'] = access_token.token if access_token
98
+ result
99
+ end
100
+ end
101
+ end
102
+ end
103
+
104
+ OmniAuth.config.add_camelization 'ekuaishou', 'Ekuaishou'
@@ -0,0 +1,28 @@
1
+ require_relative 'lib/omniauth-ekuaishou/version'
2
+
3
+ Gem::Specification.new do |spec|
4
+ spec.name = "omniauth-ekuaishou"
5
+ spec.version = OmniAuth::Ekuaishou::VERSION
6
+ spec.authors = ["jimcheung"]
7
+ spec.email = ["hi.jinhu.zhang@gmail.com"]
8
+
9
+ spec.summary = %q{Omniauth strategy for Kuaishou Marketing}
10
+ spec.description = %q{Wrapper the Kuaishou Marketing Oauth2 API}
11
+ spec.homepage = "https://github.com/jinhucheung/omniauth-ekuaishou"
12
+ spec.license = "MIT"
13
+
14
+ spec.metadata["homepage_uri"] = spec.homepage
15
+ spec.metadata["source_code_uri"] = "https://github.com/jinhucheung/omniauth-ekuaishou"
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-ekuaishou
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-14 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 Kuaishou 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-ekuaishou.rb
59
+ - lib/omniauth-ekuaishou/access_token.rb
60
+ - lib/omniauth-ekuaishou/version.rb
61
+ - lib/omniauth/strategies/ekuaishou.rb
62
+ - omniauth-ekuaishou.gemspec
63
+ homepage: https://github.com/jinhucheung/omniauth-ekuaishou
64
+ licenses:
65
+ - MIT
66
+ metadata:
67
+ homepage_uri: https://github.com/jinhucheung/omniauth-ekuaishou
68
+ source_code_uri: https://github.com/jinhucheung/omniauth-ekuaishou
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 Kuaishou Marketing
88
+ test_files: []