omniauth-tiktok-loginkit 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.rspec +3 -0
- data/.rubocop.yml +13 -0
- data/.ruby-version +1 -0
- data/CHANGELOG.md +5 -0
- data/LICENSE.txt +21 -0
- data/README.md +55 -0
- data/Rakefile +12 -0
- data/lib/omniauth/strategies/tiktok_loginkit.rb +93 -0
- data/lib/omniauth-tiktok-loginkit/version.rb +5 -0
- data/lib/omniauth-tiktok-loginkit.rb +11 -0
- metadata +98 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: d8b2ffe72f53ccfa1b75591363546ab768d90a4e65adc542f52d17e7afcfb03c
|
4
|
+
data.tar.gz: a2868ee84dee7346d1e16fe1fda4fee4ccf6c25f3b89f452b36d0ea4bed9daea
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 0bacb2d0421d4792a4a785a10729c9d7ec99403ef0fdc7e0f0cc0baeef5f8915ef4caea73a77a76c269a04e0d9006aaa6e3d9488faff6a8612ce0d3a876b617d
|
7
|
+
data.tar.gz: a8cffef59a1af571f071b76cf380fc16bed369b0bd6e7600409a5b88d25dcf0b0d6160b75650c21d7eb80596d25e3bcb0daf5a94f09e268397e6f1ec25ab8c99
|
data/.rspec
ADDED
data/.rubocop.yml
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
AllCops:
|
2
|
+
NewCops: disable
|
3
|
+
SuggestExtensions: false
|
4
|
+
|
5
|
+
Style/StringLiterals:
|
6
|
+
EnforcedStyle: double_quotes
|
7
|
+
|
8
|
+
Style/StringLiteralsInInterpolation:
|
9
|
+
EnforcedStyle: double_quotes
|
10
|
+
|
11
|
+
Naming/FileName:
|
12
|
+
Exclude:
|
13
|
+
- 'lib/omniauth-tiktok-loginkit.rb'
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
2.7.8
|
data/CHANGELOG.md
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2024 Michael Yin
|
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,55 @@
|
|
1
|
+
# omniauth-tiktok-loginkit
|
2
|
+
|
3
|
+
OmniAuth Strategy for TikTok [LoginKit](https://developers.tiktok.com/doc/login-kit-overview/)
|
4
|
+
|
5
|
+
Using TikTok Oauth API v2.
|
6
|
+
|
7
|
+
## Config
|
8
|
+
|
9
|
+
Configure with CLIENT_KEY and CLIENT_SECRET from TikTok Developers Portal (https://developers.tiktok.com/apps/). Note CLIENT_KEY is the value of "Client Key" field, not "App ID" on the portal.
|
10
|
+
|
11
|
+
TikTok requires apps to be approved by review before it can access any APIs, including the Oauth APIs. Also any configuration change to the app will cause it to be back in "Staging" status. So please configure all neccessary "Redirect URI" correctly before submitting a review.
|
12
|
+
|
13
|
+
TikTok also rejects any "Test App", so it's better to configure test / dev environment redirect URI on the production app.
|
14
|
+
|
15
|
+
```
|
16
|
+
Rails.application.config.middleware.use OmniAuth::Builder do
|
17
|
+
provider(
|
18
|
+
:tiktok_loginkit,
|
19
|
+
CLIENT_KEY,
|
20
|
+
CLIENT_SECRET,
|
21
|
+
*options
|
22
|
+
)
|
23
|
+
end
|
24
|
+
```
|
25
|
+
|
26
|
+
...Or with devise (https://github.com/heartcombo/devise#omniauth)
|
27
|
+
|
28
|
+
```
|
29
|
+
# config/initializers/devise.rb
|
30
|
+
config.omniauth(
|
31
|
+
:tiktok_loginkit,
|
32
|
+
CLIENT_KEY,
|
33
|
+
CLIENT_SECRET,
|
34
|
+
...options
|
35
|
+
)
|
36
|
+
|
37
|
+
```
|
38
|
+
|
39
|
+
## Options
|
40
|
+
|
41
|
+
* `name`: change endpoint to /auth/tiktok_another, /auth/tiktok_another/callback. default: `"tiktok_login"`
|
42
|
+
* `skip_info`: skip User Info API call to retrieve `info` hash. default: `false`
|
43
|
+
* `scope`: oauth scopes, seperated by comma. default: `"user.info.basic"`
|
44
|
+
|
45
|
+
|
46
|
+
## Usage
|
47
|
+
|
48
|
+
Example of `request.env["omniauth.auth"]` can be found in the specs:
|
49
|
+
|
50
|
+
* [with default scope: user.info.basic](https://github.com/layerssss/omniauth-tiktok-loginkit/blob/main/spec/omniauth/strategies/tiktok_loginkit_spec.rb#L108)
|
51
|
+
* [more detailed user info with scopes: user.info.basic,user.info.profile](https://github.com/layerssss/omniauth-tiktok-loginkit/blob/main/spec/omniauth/strategies/tiktok_loginkit_spec.rb#L263)
|
52
|
+
|
53
|
+
## License
|
54
|
+
|
55
|
+
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,93 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "oauth2"
|
4
|
+
require "omniauth-oauth2"
|
5
|
+
|
6
|
+
module OmniAuth
|
7
|
+
module Strategies
|
8
|
+
class TiktokLoginkit < OmniAuth::Strategies::OAuth2 # rubocop:disable Style/Documentation
|
9
|
+
class AccessToken < ::OAuth2::AccessToken
|
10
|
+
end
|
11
|
+
|
12
|
+
class NoAuthorizationCodeError < StandardError; end
|
13
|
+
USER_INFO_URL = "https://open.tiktokapis.com/v2/user/info/"
|
14
|
+
|
15
|
+
option :name, "tiktok-loginkit"
|
16
|
+
args %i[client_key client_secret]
|
17
|
+
|
18
|
+
option :client_options, {
|
19
|
+
site: "https://www.tiktok.com",
|
20
|
+
authorize_url: "https://www.tiktok.com/v2/auth/authorize/",
|
21
|
+
token_url: "https://open.tiktokapis.com/v2/oauth/token/",
|
22
|
+
auth_scheme: :request_body,
|
23
|
+
access_token_class: OmniAuth::Strategies::TiktokLoginkit::AccessToken
|
24
|
+
}
|
25
|
+
option "scope", "user.info.basic"
|
26
|
+
|
27
|
+
uid { access_token.params.fetch("open_id") }
|
28
|
+
|
29
|
+
# https://github.com/omniauth/omniauth/wiki/Auth-Hash-Schema
|
30
|
+
info do
|
31
|
+
hash = {
|
32
|
+
name: user_info.fetch("display_name"),
|
33
|
+
image: user_info.fetch("avatar_url_100")
|
34
|
+
}
|
35
|
+
if request.params.fetch("scopes").include?("user.info.profile")
|
36
|
+
hash.merge!(
|
37
|
+
nickname: user_info.fetch("username"),
|
38
|
+
description: user_info.fetch("bio_description"),
|
39
|
+
urls: {
|
40
|
+
"TikTok" => user_info.fetch("profile_web_link"),
|
41
|
+
"TikTok Deep Link" => user_info.fetch("profile_deep_link")
|
42
|
+
}
|
43
|
+
)
|
44
|
+
end
|
45
|
+
hash
|
46
|
+
end
|
47
|
+
|
48
|
+
extra do
|
49
|
+
user_info
|
50
|
+
end
|
51
|
+
|
52
|
+
def authorize_params
|
53
|
+
super.tap do |params|
|
54
|
+
params[:client_key] = options.client_key
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
def token_params
|
59
|
+
super.tap do |params|
|
60
|
+
params[:client_key] = options.client_key
|
61
|
+
params[:client_secret] = options.client_secret
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
def callback_url
|
66
|
+
full_host + callback_path
|
67
|
+
end
|
68
|
+
|
69
|
+
private
|
70
|
+
|
71
|
+
def user_info # rubocop:disable Metrics/MethodLength
|
72
|
+
return {} if skip_info?
|
73
|
+
|
74
|
+
@user_info ||= begin
|
75
|
+
fields = %w[open_id avatar_url avatar_url_100 display_name]
|
76
|
+
scopes = request.params.fetch("scopes")
|
77
|
+
if scopes.include?("user.info.profile")
|
78
|
+
fields.push("profile_web_link", "profile_deep_link", "bio_description", "is_verified", "username")
|
79
|
+
end
|
80
|
+
response = access_token
|
81
|
+
.get(
|
82
|
+
USER_INFO_URL,
|
83
|
+
params: {
|
84
|
+
fields: fields.join(",")
|
85
|
+
}
|
86
|
+
)
|
87
|
+
.parsed
|
88
|
+
response.fetch("data").fetch("user")
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
metadata
ADDED
@@ -0,0 +1,98 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: omniauth-tiktok-loginkit
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Michael Yin
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2024-04-13 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: oauth2
|
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
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '2.0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '2.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: omniauth-oauth2
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1.0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.0'
|
55
|
+
description:
|
56
|
+
email:
|
57
|
+
- layerssss@gmail.com
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- ".rspec"
|
63
|
+
- ".rubocop.yml"
|
64
|
+
- ".ruby-version"
|
65
|
+
- CHANGELOG.md
|
66
|
+
- LICENSE.txt
|
67
|
+
- README.md
|
68
|
+
- Rakefile
|
69
|
+
- lib/omniauth-tiktok-loginkit.rb
|
70
|
+
- lib/omniauth-tiktok-loginkit/version.rb
|
71
|
+
- lib/omniauth/strategies/tiktok_loginkit.rb
|
72
|
+
homepage: https://github.com/layerssss/omniauth-tiktok-loginkit.git
|
73
|
+
licenses:
|
74
|
+
- MIT
|
75
|
+
metadata:
|
76
|
+
homepage_uri: https://github.com/layerssss/omniauth-tiktok-loginkit
|
77
|
+
source_code_uri: https://github.com/layerssss/omniauth-tiktok-loginkit
|
78
|
+
changelog_uri: https://github.com/layerssss/omniauth-tiktok-loginkit/blob/main/CHANGELOG.md
|
79
|
+
post_install_message:
|
80
|
+
rdoc_options: []
|
81
|
+
require_paths:
|
82
|
+
- lib
|
83
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
84
|
+
requirements:
|
85
|
+
- - ">="
|
86
|
+
- !ruby/object:Gem::Version
|
87
|
+
version: 2.7.0
|
88
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
89
|
+
requirements:
|
90
|
+
- - ">="
|
91
|
+
- !ruby/object:Gem::Version
|
92
|
+
version: '0'
|
93
|
+
requirements: []
|
94
|
+
rubygems_version: 3.1.6
|
95
|
+
signing_key:
|
96
|
+
specification_version: 4
|
97
|
+
summary: OmniAuth Strategy for TikTok LoginKit
|
98
|
+
test_files: []
|