omniauth-tiktok 1.0.0

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: 605ac0a6e7f34e67d8426313c79d802029c7fe0f1b3413a71edc7a6d06292c9f
4
+ data.tar.gz: '087b9eabf3d933b5d74406e5eb3d0061c25246264648d0a1d0680ac399983e37'
5
+ SHA512:
6
+ metadata.gz: 9e1705b35333cf847254890806145eb5566b0ffb737e1c19c2f558f2e03f7d026f2fa276fcf8667be51b5e879a9a15d36ed092e7ed929d57db57b3b307f6ba50
7
+ data.tar.gz: e45079228dbc889f74ab9baf034a447bbef883eea9ca687ecda15f313c53b0525c801e012f0ade4f6f85d51a3c3c977b19ac1c3c576aaae77d00ae5826b3c677
@@ -0,0 +1,31 @@
1
+ name: Specs
2
+
3
+ on:
4
+ pull_request:
5
+ branches:
6
+ - '*'
7
+ push:
8
+ branches:
9
+ - develop
10
+ - master
11
+
12
+ jobs:
13
+ test:
14
+ runs-on: ubuntu-18.04
15
+
16
+ steps:
17
+ - uses: actions/checkout@v2
18
+ - name: Set up Ruby
19
+ uses: ruby/setup-ruby@v1
20
+ with:
21
+ ruby-version: 3.0
22
+ bundler-cache: true
23
+
24
+ - name: Run RSpec
25
+ run: |
26
+ bundle exec rspec
27
+
28
+ - name: Run linters
29
+ run: |
30
+ bundle exec rubocop --parallel
31
+ continue-on-error: false
data/.gitignore ADDED
@@ -0,0 +1,15 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+ Gemfile.lock
10
+
11
+ # rspec failure tracking
12
+ .rspec_status
13
+ .ruby-gemset
14
+ .ruby-version
15
+ /.idea/
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.rubocop.yml ADDED
@@ -0,0 +1,24 @@
1
+ inherit_gem:
2
+ rubocop-github:
3
+ - config/default_edge.yml
4
+ AllCops:
5
+ Exclude:
6
+ - 'bin/**/*'
7
+ - '.git/**/*'
8
+ - 'vendor/**/*'
9
+
10
+ Style/StringLiterals:
11
+ EnforcedStyle: single_quotes
12
+ Style/Documentation:
13
+ Enabled: false
14
+ Naming/VariableNumber:
15
+ Enabled: false
16
+ Naming/FileName:
17
+ Enabled: false
18
+ Gemspec/RequiredRubyVersion:
19
+ Enabled: false
20
+
21
+ Metrics/BlockLength:
22
+ Exclude:
23
+ - 'spec/**/*.rb'
24
+ - '**/*.gemspec'
@@ -0,0 +1,84 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone, regardless of age, body size, visible or invisible disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, religion, or sexual identity and orientation.
6
+
7
+ We pledge to act and interact in ways that contribute to an open, welcoming, diverse, inclusive, and healthy community.
8
+
9
+ ## Our Standards
10
+
11
+ Examples of behavior that contributes to a positive environment for our community include:
12
+
13
+ * Demonstrating empathy and kindness toward other people
14
+ * Being respectful of differing opinions, viewpoints, and experiences
15
+ * Giving and gracefully accepting constructive feedback
16
+ * Accepting responsibility and apologizing to those affected by our mistakes, and learning from the experience
17
+ * Focusing on what is best not just for us as individuals, but for the overall community
18
+
19
+ Examples of unacceptable behavior include:
20
+
21
+ * The use of sexualized language or imagery, and sexual attention or
22
+ advances of any kind
23
+ * Trolling, insulting or derogatory comments, and personal or political attacks
24
+ * Public or private harassment
25
+ * Publishing others' private information, such as a physical or email
26
+ address, without their explicit permission
27
+ * Other conduct which could reasonably be considered inappropriate in a
28
+ professional setting
29
+
30
+ ## Enforcement Responsibilities
31
+
32
+ Community leaders are responsible for clarifying and enforcing our standards of acceptable behavior and will take appropriate and fair corrective action in response to any behavior that they deem inappropriate, threatening, offensive, or harmful.
33
+
34
+ Community leaders have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, and will communicate reasons for moderation decisions when appropriate.
35
+
36
+ ## Scope
37
+
38
+ This Code of Conduct applies within all community spaces, and also applies when an individual is officially representing the community in public spaces. Examples of representing our community include using an official e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event.
39
+
40
+ ## Enforcement
41
+
42
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community leaders responsible for enforcement at novikov@oneclick.life. All complaints will be reviewed and investigated promptly and fairly.
43
+
44
+ All community leaders are obligated to respect the privacy and security of the reporter of any incident.
45
+
46
+ ## Enforcement Guidelines
47
+
48
+ Community leaders will follow these Community Impact Guidelines in determining the consequences for any action they deem in violation of this Code of Conduct:
49
+
50
+ ### 1. Correction
51
+
52
+ **Community Impact**: Use of inappropriate language or other behavior deemed unprofessional or unwelcome in the community.
53
+
54
+ **Consequence**: A private, written warning from community leaders, providing clarity around the nature of the violation and an explanation of why the behavior was inappropriate. A public apology may be requested.
55
+
56
+ ### 2. Warning
57
+
58
+ **Community Impact**: A violation through a single incident or series of actions.
59
+
60
+ **Consequence**: A warning with consequences for continued behavior. No interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, for a specified period of time. This includes avoiding interactions in community spaces as well as external channels like social media. Violating these terms may lead to a temporary or permanent ban.
61
+
62
+ ### 3. Temporary Ban
63
+
64
+ **Community Impact**: A serious violation of community standards, including sustained inappropriate behavior.
65
+
66
+ **Consequence**: A temporary ban from any sort of interaction or public communication with the community for a specified period of time. No public or private interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, is allowed during this period. Violating these terms may lead to a permanent ban.
67
+
68
+ ### 4. Permanent Ban
69
+
70
+ **Community Impact**: Demonstrating a pattern of violation of community standards, including sustained inappropriate behavior, harassment of an individual, or aggression toward or disparagement of classes of individuals.
71
+
72
+ **Consequence**: A permanent ban from any sort of public interaction within the community.
73
+
74
+ ## Attribution
75
+
76
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 2.0,
77
+ available at https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
78
+
79
+ Community Impact Guidelines were inspired by [Mozilla's code of conduct enforcement ladder](https://github.com/mozilla/diversity).
80
+
81
+ [homepage]: https://www.contributor-covenant.org
82
+
83
+ For answers to common questions about this code of conduct, see the FAQ at
84
+ https://www.contributor-covenant.org/faq. Translations are available at https://www.contributor-covenant.org/translations.
data/Gemfile ADDED
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ source 'https://rubygems.org'
4
+
5
+ # Specify your gem's dependencies in omniauth-tiktok.gemspec
6
+ gemspec
7
+
8
+ gem 'rake', '~> 13.0'
9
+ gem 'rspec'
10
+ gem 'rubocop'
11
+ gem 'rubocop-github'
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2020 Vasiliy Novikov
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,67 @@
1
+ Tiktok OAuth2 Strategy for OmniAuth.
2
+
3
+ Supports OAuth 2.0 server-side flow with Tiktok API.
4
+ Read the Tiktok docs for more details: https://developers.tiktok.com/doc/login-kit-web
5
+
6
+ ####Tiktok access_token valid only for 24 hours!
7
+
8
+ ## Installing
9
+
10
+ Add to your `Gemfile`:
11
+
12
+ ```ruby
13
+ gem 'omniauth-tiktok'
14
+ ```
15
+
16
+ Then `bundle install`.
17
+
18
+ ## Usage
19
+
20
+ `OmniAuth::Strategies::Tiktok` is simply a Rack middleware. Read the OmniAuth docs for detailed instructions: https://github.com/omniauth/omniauth.
21
+
22
+ Here's a quick example, 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, ENV['TIKTOK_CLIENT_ID'], ENV['TIKTOK_CLIENT_SECRET']
27
+ end
28
+ ```
29
+
30
+ ### Custom Callback URL/Path
31
+
32
+ You can set a custom `callback_url` or `callback_path` option to override the default value.
33
+
34
+ ## Auth Hash
35
+
36
+ Here's an example Auth Hash available in `request.env['omniauth.auth']`:
37
+
38
+ ```
39
+ {
40
+ provider: 'tiktok',
41
+ uid: '1234567',
42
+ info: {
43
+ display_name: 'ABCDEF'
44
+ },
45
+ credentials: {
46
+ token: 'ABCDEF...', # OAuth 2.0 access_token, which you may wish to store
47
+ expires_at: 1321747205, # when the access token expires (it always will)
48
+ expires: true, # this will always be true
49
+ refresh_token: 'ABCDEF', # it will be valid for 365 days
50
+ refresh_token_expires_at: 1111111 # timestamp
51
+ }
52
+ }
53
+ ```
54
+
55
+ ## Development
56
+
57
+ ```
58
+ gem bump --file=lib/omniauth-tiktok/version.rb --push --tag --release --pretend
59
+ ```
60
+
61
+ ## License
62
+
63
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
64
+
65
+ ## Code of Conduct
66
+
67
+ Everyone interacting in the OmniAuth::Tiktok project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/Lianowar/omniauth-tiktok/blob/master/CODE_OF_CONDUCT.md).
data/Rakefile ADDED
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'bundler/gem_tasks'
4
+ require 'rspec/core/rake_task'
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ require 'rubocop/rake_task'
9
+
10
+ RuboCop::RakeTask.new
11
+
12
+ task default: %i[spec rubocop]
data/bin/console ADDED
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require "bundler/setup"
5
+ require "omniauth/tiktok"
6
+
7
+ # You can add fixtures and/or initialization code here to make experimenting
8
+ # with your gem easier. You can also use a different console, if you like.
9
+
10
+ # (If you use this, don't forget to add pry to your Gemfile!)
11
+ # require "pry"
12
+ # Pry.start
13
+
14
+ require "irb"
15
+ 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,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'omniauth-tiktok/version'
4
+ require 'omniauth/strategies/tiktok'
5
+
6
+ module Omniauth
7
+ module Tiktok
8
+ class Error < StandardError; end
9
+ # Your code goes here...
10
+ end
11
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Omniauth
4
+ module Tiktok
5
+ VERSION = '1.0.0'
6
+ end
7
+ end
@@ -0,0 +1,86 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'omniauth/strategies/oauth2'
4
+
5
+ module OmniAuth
6
+ module Strategies
7
+ class Tiktok < OmniAuth::Strategies::OAuth2
8
+ class NoAuthorizationCodeError < StandardError; end
9
+ DEFAULT_SCOPE = 'user.info.basic,video.list'
10
+ USER_INFO_URL = 'https://open-api.tiktok.com/oauth/userinfo'
11
+
12
+ option :name, 'tiktok'
13
+
14
+ option :client_options, {
15
+ site: 'https://open-api.tiktok.com',
16
+ authorize_url: 'https://open-api.tiktok.com/platform/oauth/connect',
17
+ token_url: 'https://open-api.tiktok.com/oauth/access_token',
18
+ extract_access_token: proc do |client, hash|
19
+ hash = hash['data']
20
+ token = hash.delete('access_token') || hash.delete(:access_token)
21
+ token && ::OAuth2::AccessToken.new(client, token, hash)
22
+ end
23
+ }
24
+
25
+ option :authorize_options, %i[scope display auth_type]
26
+
27
+ uid { access_token.params['open_id'] }
28
+
29
+ info do
30
+ prune!('nickname' => raw_info['data']['display_name'])
31
+ end
32
+
33
+ extra do
34
+ hash = {}
35
+ hash['raw_info'] = raw_info unless skip_info?
36
+ prune! hash
37
+ end
38
+
39
+ credentials do
40
+ hash = {}
41
+ hash['token'] = access_token.token
42
+ hash['refresh_token'] = access_token.refresh_token if access_token.expires? && access_token.refresh_token
43
+ hash['expires_at'] = access_token.expires_at if access_token.expires?
44
+ hash['expires'] = access_token.expires?
45
+ refresh_token_expires_at = Time.now.to_i + access_token.params['refresh_expires_in'].to_i
46
+ hash['refresh_token_expires_at'] = refresh_token_expires_at
47
+ hash
48
+ end
49
+
50
+ def raw_info
51
+ @raw_info ||= access_token
52
+ .get("#{USER_INFO_URL}?open_id=#{access_token.params['open_id']}&access_token=#{access_token.token}")
53
+ .parsed || {}
54
+ end
55
+
56
+ def callback_url
57
+ options[:callback_url] || (full_host + script_name + callback_path)
58
+ end
59
+
60
+ def authorize_params
61
+ super.tap do |params|
62
+ params[:scope] ||= DEFAULT_SCOPE
63
+ params[:response_type] = 'code'
64
+ params.delete(:client_id)
65
+ params[:client_key] = options.client_id
66
+ end
67
+ end
68
+
69
+ def token_params
70
+ super.tap do |params|
71
+ params.delete(:client_id)
72
+ params[:client_key] = options.client_id
73
+ end
74
+ end
75
+
76
+ private
77
+
78
+ def prune!(hash)
79
+ hash.delete_if do |_, value|
80
+ prune!(value) if value.is_a?(Hash)
81
+ value.nil? || (value.respond_to?(:empty?) && value.empty?)
82
+ end
83
+ end
84
+ end
85
+ end
86
+ end
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'lib/omniauth-tiktok/version'
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = 'omniauth-tiktok'
7
+ spec.version = Omniauth::Tiktok::VERSION
8
+ spec.authors = ['novikov.vasiliy']
9
+ spec.email = ['novikov.vasiliy.d@gmail.com']
10
+
11
+ spec.summary = 'Tiktok OAuth2 Strategy for OmniAuth'
12
+ spec.homepage = 'https://github.com/Lianowar/omniauth-tiktok'
13
+ spec.license = 'MIT'
14
+ spec.required_ruby_version = Gem::Requirement.new('>= 2.6.0')
15
+
16
+ spec.metadata['homepage_uri'] = spec.homepage
17
+ spec.metadata['source_code_uri'] = 'https://github.com/Lianowar/omniauth-tiktok'
18
+
19
+ # Specify which files should be added to the gem when it is released.
20
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
21
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
22
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{\A(?:test|spec|features)/}) }
23
+ end
24
+ spec.bindir = 'exe'
25
+ spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
26
+ spec.require_paths = ['lib']
27
+
28
+ spec.add_runtime_dependency 'omniauth', '~> 1.9'
29
+ spec.add_runtime_dependency 'omniauth-oauth2', '~> 1.2'
30
+ end
metadata ADDED
@@ -0,0 +1,88 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: omniauth-tiktok
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - novikov.vasiliy
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2021-06-21 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: '1.9'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.9'
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.2'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.2'
41
+ description:
42
+ email:
43
+ - novikov.vasiliy.d@gmail.com
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - ".github/workflows/specs.yml"
49
+ - ".gitignore"
50
+ - ".rspec"
51
+ - ".rubocop.yml"
52
+ - CODE_OF_CONDUCT.md
53
+ - Gemfile
54
+ - LICENSE.txt
55
+ - README.md
56
+ - Rakefile
57
+ - bin/console
58
+ - bin/setup
59
+ - lib/omniauth-tiktok.rb
60
+ - lib/omniauth-tiktok/version.rb
61
+ - lib/omniauth/strategies/tiktok.rb
62
+ - omniauth-tiktok.gemspec
63
+ homepage: https://github.com/Lianowar/omniauth-tiktok
64
+ licenses:
65
+ - MIT
66
+ metadata:
67
+ homepage_uri: https://github.com/Lianowar/omniauth-tiktok
68
+ source_code_uri: https://github.com/Lianowar/omniauth-tiktok
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: 2.6.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.2.15
85
+ signing_key:
86
+ specification_version: 4
87
+ summary: Tiktok OAuth2 Strategy for OmniAuth
88
+ test_files: []