omniauth-tiktok_business-oauth2 1.0.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/.gitignore +8 -0
- data/Gemfile +3 -0
- data/LICENSE +21 -0
- data/README.md +34 -0
- data/Rakefile +2 -0
- data/lib/omniauth/strategies/tiktok_business_oauth2.rb +89 -0
- data/lib/omniauth-tiktok_business-oauth2/version.rb +3 -0
- data/lib/omniauth-tiktok_business-oauth2.rb +9 -0
- data/omniauth-tiktok_business-oauth2.gemspec +19 -0
- metadata +94 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 2f2f9c124c2231c56b4463696cf44b0d284f65049c5e95bb0752929f3072a9e5
|
4
|
+
data.tar.gz: 58bdf534f93a729b097e659420cf83348a6b4e67706fd81d570578e87ae895bc
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 7d40c9e41e07b376fa5b76dd38234e3e75737b27d7dc686c4ce2160d53ec1aa327e0c489c4df1fcc0f7f059144c5c262881807a22f563988eb04e0919c455833
|
7
|
+
data.tar.gz: 6887e416a7818cb62fe4c7c548ef21de20057baf217894018b1dfdc9110bd44494204f63521ff841be74566a126677c7f90ca64c45611a2a00629417105f2145
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2023 Damian Aberbuj
|
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,34 @@
|
|
1
|
+
# OmniAuth TikTok (Accounts API) OAuth2 Strategy
|
2
|
+
Strategy to authenticate with TikTok (Accounts API) via OAuth2 in OmniAuth
|
3
|
+
|
4
|
+
Sign up and create your Application https://business-api.tiktok.com/portal/docs?id=1760334598980610.
|
5
|
+
Note the App ID and the App Secret.
|
6
|
+
|
7
|
+
For more details, read the docs:
|
8
|
+
https://business-api.tiktok.com/portal/docs?id=1735713875563521
|
9
|
+
|
10
|
+
## Installation
|
11
|
+
|
12
|
+
Add to your `Gemfile`:
|
13
|
+
|
14
|
+
```ruby
|
15
|
+
gem 'omniauth-tiktok_business-oauth2'
|
16
|
+
```
|
17
|
+
|
18
|
+
Then `bundle install`.
|
19
|
+
|
20
|
+
## Usage
|
21
|
+
|
22
|
+
Here's an example for adding the middleware to a Rails app in `config/initializers/omniauth.rb`:
|
23
|
+
|
24
|
+
```ruby
|
25
|
+
Rails.application.config.middleware.use OmniAuth::Builder do
|
26
|
+
provider :tiktok_business_oauth2, ENV['TIKTOK_APP_ID'], ENV['TIKTOK_SECRET']
|
27
|
+
end
|
28
|
+
```
|
29
|
+
|
30
|
+
You can now access the OmniAuth TikTok OAuth2 URL: `/auth/tiktok_business_oauth2`
|
31
|
+
|
32
|
+
## Configuration
|
33
|
+
|
34
|
+
* `name`: The name of the strategy. The default name is `tiktok_business_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`.
|
data/Rakefile
ADDED
@@ -0,0 +1,89 @@
|
|
1
|
+
module OmniAuth
|
2
|
+
module Strategies
|
3
|
+
class TiktokBusinessOauth2 < OmniAuth::Strategies::OAuth2
|
4
|
+
USER_INFO_URL = 'https://business-api.tiktok.com/open_api/v1.3/business/get/'
|
5
|
+
USER_FIELDS = '["username","display_name","profile_image","is_business_account"]'
|
6
|
+
|
7
|
+
option :name, "tiktok_business_oauth2"
|
8
|
+
option :client_options,
|
9
|
+
site: 'https://business-api.tiktok.com/',
|
10
|
+
authorize_url: 'https://www.tiktok.com/v2/auth/authorize/',
|
11
|
+
token_url: 'https://business-api.tiktok.com/open_api/v1.3/tt_user/oauth2/token/'
|
12
|
+
|
13
|
+
option :pkce, true
|
14
|
+
|
15
|
+
def authorize_params
|
16
|
+
super.tap do |params|
|
17
|
+
params[:client_key] = options.client_id
|
18
|
+
params[:scope] = 'user.info.basic,user.info.username,user.info.stats,user.account.type,user.insights,video.list,video.insights,comment.list,comment.list.manage'
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
uid do
|
23
|
+
raw_info['open_id']
|
24
|
+
end
|
25
|
+
|
26
|
+
info do
|
27
|
+
{
|
28
|
+
id: raw_info['open_id'],
|
29
|
+
name: raw_info['user']['display_name'],
|
30
|
+
username: raw_info['user']['username'],
|
31
|
+
profile_image: raw_info['user']['profile_image'],
|
32
|
+
is_business_account: raw_info['user']['is_business_account']
|
33
|
+
}
|
34
|
+
end
|
35
|
+
|
36
|
+
extra do
|
37
|
+
{
|
38
|
+
'raw_info' => raw_info
|
39
|
+
}
|
40
|
+
end
|
41
|
+
|
42
|
+
# # Remove params as callback URL must match exactly the URL defined for the application
|
43
|
+
def callback_url
|
44
|
+
super.split('?').first
|
45
|
+
end
|
46
|
+
|
47
|
+
def token_params
|
48
|
+
options.token_params.merge(
|
49
|
+
headers: { 'Content-Type' => 'application/json' },
|
50
|
+
client_id: options.client_id,
|
51
|
+
client_secret: options.client_secret,
|
52
|
+
auth_code: request.params["code"],
|
53
|
+
parse: :tiktok_business,
|
54
|
+
)
|
55
|
+
end
|
56
|
+
|
57
|
+
def raw_info
|
58
|
+
@raw_info ||= access_token_info.merge('user' => tiktok_user_info)
|
59
|
+
end
|
60
|
+
|
61
|
+
def tiktok_user_info
|
62
|
+
@tiktok_user_info ||= begin
|
63
|
+
headers = {
|
64
|
+
'Access-Token' => access_token.token
|
65
|
+
}
|
66
|
+
|
67
|
+
params = {
|
68
|
+
business_id: access_token_info['open_id'],
|
69
|
+
fields: USER_FIELDS
|
70
|
+
}
|
71
|
+
|
72
|
+
access_token.get(USER_INFO_URL, headers: headers, params: params, parse: :tiktok_business).parsed
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
def access_token_info
|
77
|
+
access_token.to_hash.stringify_keys
|
78
|
+
end
|
79
|
+
|
80
|
+
# It is necessary to override this method to avoid the "Content-Type" string getting turned into a symbol.
|
81
|
+
# Unfortunately you can't just pass headers in `token_params` method because the original `build_access_token` deep symbolizes all parameters, and the OAuth2 gem expects the headers to be strings
|
82
|
+
def build_access_token
|
83
|
+
verifier = request.params["code"]
|
84
|
+
client.auth_code.get_token(verifier, {:redirect_uri => callback_url}.merge(token_params), deep_symbolize(options.auth_token_params))
|
85
|
+
end
|
86
|
+
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
@@ -0,0 +1,9 @@
|
|
1
|
+
require 'oauth2'
|
2
|
+
require 'omniauth/strategies/oauth2'
|
3
|
+
|
4
|
+
require 'omniauth-tiktok_business-oauth2/version'
|
5
|
+
require 'omniauth/strategies/tiktok_business_oauth2'
|
6
|
+
|
7
|
+
OAuth2::Response.register_parser(:tiktok_business, []) do |body|
|
8
|
+
JSON.parse(body).fetch('data') rescue body
|
9
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require_relative 'lib/omniauth-tiktok_business-oauth2/version'
|
2
|
+
|
3
|
+
Gem::Specification.new do |gem|
|
4
|
+
gem.name = 'omniauth-tiktok_business-oauth2'
|
5
|
+
gem.version = OmniAuthTiktokBusinessOauth2::VERSION
|
6
|
+
gem.license = 'MIT'
|
7
|
+
gem.summary = %(A TikTok Business API OAuth2 strategy for OmniAuth)
|
8
|
+
gem.description = %(A TikTok Business API OAuth2 strategy for OmniAuth. This allows you to login with TikTok in your ruby app.)
|
9
|
+
gem.authors = ['Damian Aberbuj']
|
10
|
+
gem.homepage = 'https://github.com/daberbuj/omniauth-tiktok_business-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
|
+
|
18
|
+
gem.add_development_dependency 'rake'
|
19
|
+
end
|
metadata
ADDED
@@ -0,0 +1,94 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: omniauth-tiktok_business-oauth2
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Damian Aberbuj
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2023-12-11 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
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
description: A TikTok Business API OAuth2 strategy for OmniAuth. This allows you to
|
56
|
+
login with TikTok in your ruby app.
|
57
|
+
email:
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- ".gitignore"
|
63
|
+
- Gemfile
|
64
|
+
- LICENSE
|
65
|
+
- README.md
|
66
|
+
- Rakefile
|
67
|
+
- lib/omniauth-tiktok_business-oauth2.rb
|
68
|
+
- lib/omniauth-tiktok_business-oauth2/version.rb
|
69
|
+
- lib/omniauth/strategies/tiktok_business_oauth2.rb
|
70
|
+
- omniauth-tiktok_business-oauth2.gemspec
|
71
|
+
homepage: https://github.com/daberbuj/omniauth-tiktok_business-oauth2
|
72
|
+
licenses:
|
73
|
+
- MIT
|
74
|
+
metadata: {}
|
75
|
+
post_install_message:
|
76
|
+
rdoc_options: []
|
77
|
+
require_paths:
|
78
|
+
- lib
|
79
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
80
|
+
requirements:
|
81
|
+
- - ">="
|
82
|
+
- !ruby/object:Gem::Version
|
83
|
+
version: '0'
|
84
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
85
|
+
requirements:
|
86
|
+
- - ">="
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
version: '0'
|
89
|
+
requirements: []
|
90
|
+
rubygems_version: 3.3.26
|
91
|
+
signing_key:
|
92
|
+
specification_version: 4
|
93
|
+
summary: A TikTok Business API OAuth2 strategy for OmniAuth
|
94
|
+
test_files: []
|