omniauth-tiktok-oauth2 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 1cee8a6f58251444de9f7aa3275e934b9d18ac810231f67a72656107262a0e44
4
+ data.tar.gz: a4eeeeeae20bd7b0e7c29853a612aec78135c20c0d04e9316cc1ca0c07ffcd29
5
+ SHA512:
6
+ metadata.gz: 5702d05d75b0297279ab748d93ebac390ecb5d1c838230e7870a615ce7578b9a353de099f351be822b1f31a3c7bde33b40a41e5a1c82d2173a8b45bab0527b8e
7
+ data.tar.gz: 54e6e3b59778874830c5ecfdcd933417a2380fe50142b9e8df8d99a6d77cd56bbbdb8c27db52106eac589f4bf569a675a6c5025a57a13f355d8b32264153d1a2
data/.gitignore ADDED
@@ -0,0 +1,22 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ .ruby-gemset
7
+ .ruby-version
8
+ .rvmrc
9
+ Gemfile.lock
10
+ InstalledFiles
11
+ _yardoc
12
+ coverage
13
+ doc/
14
+ lib/bundler/man
15
+ pkg
16
+ rdoc
17
+ spec/reports
18
+ test/tmp
19
+ test/version_tmp
20
+ tmp
21
+ .powenv
22
+ .idea/
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source "https://rubygems.org"
2
+
3
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2021 Kristoffer Ek
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 all
13
+ 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 THE
21
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,32 @@
1
+ # OmniAuth TikTok (Marketing API) OAuth2 Strategy
2
+ Strategy to authenticate with TikTok (Marketing API) via OAuth2 in OmniAuth
3
+
4
+ Sign up and create your Application at https://ads.tiktok.com/i18n/login. Note the App ID and the App Secret.
5
+
6
+ For more details, read the docs: https://ads.tiktok.com/marketing_api/docs?rid=1dmrkuztuhi&id=100510
7
+
8
+ ## Installation
9
+
10
+ Add to your `Gemfile`:
11
+
12
+ ```ruby
13
+ gem 'omniauth-tiktok-oauth2'
14
+ ```
15
+
16
+ Then `bundle install`.
17
+
18
+ ## Usage
19
+
20
+ Here's an example for adding the middleware to a Rails app in `config/initializers/omniauth.rb`:
21
+
22
+ ```ruby
23
+ Rails.application.config.middleware.use OmniAuth::Builder do
24
+ provider :tiktok_oauth2, ENV['TIKTOK_APP_ID'], ENV['TIKTOK_SECRET']
25
+ end
26
+ ```
27
+
28
+ You can now access the OmniAuth TikTok OAuth2 URL: `/auth/tiktok_oauth2`
29
+
30
+ ## Configuration
31
+
32
+ * `name`: The name of the strategy. The default name is `tiktok_oauth2` but it can be changed to any value, for example `tiktok`. The OmniAuth URL will thus change to `/auth/tiktok` and the `provider` key in the auth hash will then return `tiktok`.
@@ -0,0 +1,68 @@
1
+ require 'oauth2'
2
+ require 'omniauth/strategies/oauth2'
3
+
4
+ OAuth2::Response.register_parser(:tiktok, ['application/json']) do |body|
5
+ JSON.parse(body)['data']
6
+ end
7
+
8
+ module OmniAuth
9
+ module Strategies
10
+ class TiktokOauth2 < OmniAuth::Strategies::OAuth2
11
+ USER_INFO_URL = 'https://ads.tiktok.com/open_api/v1.2/user/info/'
12
+ option :name, "tiktok_oauth2"
13
+ option :client_options,
14
+ site: 'https://ads.tiktok.com',
15
+ authorize_url: 'https://ads.tiktok.com/marketing_api/auth',
16
+ token_url: 'https://ads.tiktok.com/open_api/v1.2/oauth2/access_token'
17
+
18
+ option :pkce, true
19
+
20
+ def authorize_params
21
+ super.tap do |params|
22
+ params[:app_id] = options.client_id
23
+ end
24
+ end
25
+
26
+ uid{ raw_info['id'] }
27
+
28
+ info do
29
+ {
30
+ email: raw_info['email'],
31
+ name: raw_info['display_name'],
32
+ id: raw_info['id'],
33
+ create_time: raw_info['create_time'],
34
+ }
35
+ end
36
+
37
+ extra do
38
+ {
39
+ 'raw_info' => raw_info
40
+ }
41
+ end
42
+
43
+ # Remove params as callback URL must match exactly the URL defined for the application
44
+ def callback_url
45
+ super.split('?').first
46
+ end
47
+
48
+ def token_params
49
+ options.token_params.merge(
50
+ app_id: options.client_id,
51
+ secret: options.client_secret,
52
+ auth_code: request.params["code"],
53
+ parse: :tiktok,
54
+ )
55
+ end
56
+
57
+ def raw_info
58
+ @raw_info ||= access_token.get(USER_INFO_URL, headers: headers, parse: :tiktok).parsed
59
+ end
60
+
61
+ def headers
62
+ {
63
+ 'Access-Token' => access_token.token,
64
+ }
65
+ end
66
+ end
67
+ end
68
+ end
@@ -0,0 +1,3 @@
1
+ module OmniAuthTiktokOauth2
2
+ VERSION = '0.1.4'
3
+ end
@@ -0,0 +1,2 @@
1
+ require 'omniauth-tiktok-oauth2/version'
2
+ require 'omniauth/strategies/tiktok_oauth2'
@@ -0,0 +1,17 @@
1
+ require_relative 'lib/omniauth-tiktok-oauth2/version'
2
+
3
+ Gem::Specification.new do |gem|
4
+ gem.name = 'omniauth-tiktok-oauth2'
5
+ gem.version = OmniAuthTiktokOauth2::VERSION
6
+ gem.license = 'MIT'
7
+ gem.summary = %(A TikTok Marketing API OAuth2 strategy for OmniAuth)
8
+ gem.description = %(A TikTok Marketing API OAuth2 strategy for OmniAuth. This allows you to login with TikTok in your ruby app.)
9
+ gem.authors = ['Kristoffer Ek']
10
+ gem.homepage = 'https://github.com/kristofferek/omniauth-tiktok-oauth2'
11
+
12
+ gem.files = `git ls-files`.split("\n")
13
+ gem.require_paths = ['lib']
14
+
15
+ gem.add_runtime_dependency 'omniauth-oauth2', '~> 1.6'
16
+ gem.add_runtime_dependency 'oauth2', '~> 1.1'
17
+ end
metadata ADDED
@@ -0,0 +1,80 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: omniauth-tiktok-oauth2
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.4
5
+ platform: ruby
6
+ authors:
7
+ - Kristoffer Ek
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2021-04-15 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: omniauth-oauth2
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.6'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.6'
27
+ - !ruby/object:Gem::Dependency
28
+ name: oauth2
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.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.1'
41
+ description: A TikTok Marketing API OAuth2 strategy for OmniAuth. This allows you
42
+ to login with TikTok in your ruby app.
43
+ email:
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - ".gitignore"
49
+ - Gemfile
50
+ - LICENSE
51
+ - README.md
52
+ - lib/omniauth-tiktok-oauth2.rb
53
+ - lib/omniauth-tiktok-oauth2/version.rb
54
+ - lib/omniauth/strategies/tiktok_oauth2.rb
55
+ - omniauth-tiktok-oauth2.gemspec
56
+ homepage: https://github.com/kristofferek/omniauth-tiktok-oauth2
57
+ licenses:
58
+ - MIT
59
+ metadata: {}
60
+ post_install_message:
61
+ rdoc_options: []
62
+ require_paths:
63
+ - lib
64
+ required_ruby_version: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ required_rubygems_version: !ruby/object:Gem::Requirement
70
+ requirements:
71
+ - - ">="
72
+ - !ruby/object:Gem::Version
73
+ version: '0'
74
+ requirements: []
75
+ rubyforge_project:
76
+ rubygems_version: 2.7.6.2
77
+ signing_key:
78
+ specification_version: 4
79
+ summary: A TikTok Marketing API OAuth2 strategy for OmniAuth
80
+ test_files: []