omniauth-threads-api 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: 1c548d8814dc5e198659b2a8f855fbc1b3ff91bb722cf4bbba19c139c2c918b6
4
+ data.tar.gz: c4c5db3a7b70b3956a794aad0c81042e2e3db8f61f83b034e69219585394a150
5
+ SHA512:
6
+ metadata.gz: 8be47623829b7776374574e56a7af563fa12162d07a4e6404bd3bd838b5f43119f87b5324a001a71a9e5e3d35cdb9c6ff4c20137fd5f3b6aa12811aa695581e8
7
+ data.tar.gz: 176d90df43bcd0d89aafe4836485000794d49ef2590cb90984e2915336228cf45d2d311d8dd9d9b36e1d14f76c9b986f3ea1453326f2e6931a439b99e2135e98
data/.standard.yml ADDED
@@ -0,0 +1 @@
1
+ ruby_version: 3.0
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2024 Giacomo Guiulfo Knell
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,90 @@
1
+ # Omniauth::ThreadsAPI
2
+
3
+ [![Gem Version](https://badge.fury.io/rb/omniauth-threads-api.svg)](https://badge.fury.io/rb/omniauth-threads-api)
4
+ [![Build Status](https://github.com/giacomoguiulfo/omniauth-threads-api/actions/workflows/main.yml/badge.svg)](https://github.com/giacomoguiulfo/omniauth-threads-api/actions)
5
+ [![License](https://img.shields.io/badge/license-MIT-blue.svg)](LICENSE)
6
+
7
+ An OmniAuth strategy for authenticating with the [Threads API](https://developers.facebook.com/docs/threads) via OAuth.
8
+
9
+ ## Installation
10
+
11
+ Add this line to your application's Gemfile:
12
+
13
+ ```ruby
14
+ gem 'omniauth-threads-api'
15
+ ```
16
+
17
+ And then execute:
18
+
19
+ ```bash
20
+ bundle install
21
+ ```
22
+
23
+ ## Usage
24
+
25
+ Here's an example of using it in a Rails application:
26
+
27
+ ```ruby
28
+ # config/initializers/omniauth.rb
29
+ Rails.application.config.middleware.use OmniAuth::Builder do
30
+ provider :threads, ENV['THREADS_CLIENT_ID'], ENV['THREADS_CLIENT_SECRET']
31
+ end
32
+ ```
33
+
34
+ Make sure to set `THREADS_CLIENT_ID` and `THREADS_CLIENT_SECRET` environment variables to your actual credentials or use [Rails encrypted credentials](https://guides.rubyonrails.org/security.html#custom-credentials) (e.g. `Rails.application.credentials.threads`).
35
+
36
+
37
+ ## Scopes
38
+
39
+ The default scope for this strategy is `threads_basic`. To add more scopes simply specify them after your credentials:
40
+
41
+ ```ruby
42
+ # config/initializers/omniauth.rb
43
+ Rails.application.config.middleware.use OmniAuth::Builder do
44
+ provider :threads, ENV['THREADS_CLIENT_ID'], ENV['THREADS_CLIENT_SECRET'],
45
+ scope: [
46
+ 'threads_basic',
47
+ 'threads_content_publish',
48
+ 'threads_read_replies',
49
+ 'threads_manage_replies',
50
+ 'threads_manage_insights',
51
+ ].join(",")
52
+ end
53
+ ```
54
+
55
+ ## Auth Hash
56
+
57
+ This is an example of what the [Auth Hash](https://github.com/omniauth/omniauth/wiki/Auth-Hash-Schema) available in `request.env['omniauth.auth']` would look like:
58
+
59
+ ```ruby
60
+ {
61
+ provider: 'threads',
62
+ uid: '123456789',
63
+ info: {
64
+ name: 'John Doe',
65
+ nickname: 'johndoe',
66
+ description: "I'm just a tech",
67
+ image: 'https://scontent-nrt1-1.cdninstagram.com/v/...',
68
+ },
69
+ credentials: {
70
+ token: 'qwertyuiopasdfghjklzxcvbnm',
71
+ expires: true,
72
+ expires_at: 1733097115,
73
+ },
74
+ extra: {
75
+ raw_info: {
76
+ id: "123456789",
77
+ name: "John Doe",
78
+ username: "johndoe":
79
+ threads_biography: "I'm just a tech",
80
+ threads_profile_picture_url: "https://scontent-nrt1-1.cdninstagram.com/v/..."
81
+ }
82
+ }
83
+ }
84
+ ```
85
+
86
+ The tokens stored in the `credentials` are last for 60 days and can be [refreshed](https://developers.facebook.com/docs/threads/get-started/long-lived-tokens).
87
+
88
+ ## License
89
+
90
+ 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,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "minitest/test_task"
5
+
6
+ Minitest::TestTask.create
7
+
8
+ require "standard/rake"
9
+
10
+ task default: %i[test standard]
@@ -0,0 +1,60 @@
1
+ require "omniauth-oauth2"
2
+
3
+ module OmniAuth
4
+ module Strategies
5
+ class Threads < OmniAuth::Strategies::OAuth2
6
+ DEFAULT_SCOPE = "threads_basic"
7
+ DEFAULT_FIELDS = "id,username,name,threads_profile_picture_url,threads_biography"
8
+
9
+ option :name, "threads"
10
+
11
+ option :client_options, {
12
+ site: "https://graph.threads.net/v1.0",
13
+ authorize_url: "https://threads.net/oauth/authorize",
14
+ token_url: "oauth/access_token"
15
+ }
16
+
17
+ option :scope, DEFAULT_SCOPE
18
+
19
+ uid { raw_info["id"] }
20
+
21
+ info do
22
+ {
23
+ name: raw_info["name"],
24
+ nickname: raw_info["username"],
25
+ description: raw_info["threads_biography"],
26
+ image: raw_info["threads_profile_picture_url"]
27
+ }
28
+ end
29
+
30
+ credentials do
31
+ {
32
+ token: long_lived_token.token,
33
+ expires_at: long_lived_token.expires_at,
34
+ expires: true
35
+ }
36
+ end
37
+
38
+ extra { {raw_info: raw_info} }
39
+
40
+ def token_params
41
+ super.tap do |params|
42
+ params[:client_id] = options.client_id
43
+ params[:client_secret] = options.client_secret
44
+ end
45
+ end
46
+
47
+ def callback_url
48
+ full_host + callback_path
49
+ end
50
+
51
+ def raw_info
52
+ @raw_info ||= long_lived_token.get("/me", params: {fields: DEFAULT_FIELDS}).parsed
53
+ end
54
+
55
+ def long_lived_token
56
+ @long_lived_token ||= ::OAuth2::AccessToken.from_hash(client, access_token.get("/access_token", params: {grant_type: "th_exchange_token", client_secret: options.client_secret, access_token: access_token.token}).parsed)
57
+ end
58
+ end
59
+ end
60
+ end
@@ -0,0 +1,5 @@
1
+ module OmniAuth
2
+ module ThreadsAPI
3
+ VERSION = "0.1.0"
4
+ end
5
+ end
@@ -0,0 +1,2 @@
1
+ require "omniauth-threads-api/version"
2
+ require "omniauth/strategies/threads"
metadata ADDED
@@ -0,0 +1,93 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: omniauth-threads-api
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Giacomo Guiulfo Knell
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2024-10-08 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.8'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.8'
55
+ description: An OmniAuth strategy for authenticating with the Threads API (https://developers.facebook.com/docs/threads/)
56
+ email:
57
+ - giaco@hey.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - ".standard.yml"
63
+ - LICENSE.txt
64
+ - README.md
65
+ - Rakefile
66
+ - lib/omniauth-threads-api.rb
67
+ - lib/omniauth-threads-api/version.rb
68
+ - lib/omniauth/strategies/threads.rb
69
+ homepage: https://github.com/giacomoguiulfo/omniauth-threads-api
70
+ licenses:
71
+ - MIT
72
+ metadata:
73
+ homepage_uri: https://github.com/giacomoguiulfo/omniauth-threads-api
74
+ post_install_message:
75
+ rdoc_options: []
76
+ require_paths:
77
+ - lib
78
+ required_ruby_version: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: 3.0.0
83
+ required_rubygems_version: !ruby/object:Gem::Requirement
84
+ requirements:
85
+ - - ">="
86
+ - !ruby/object:Gem::Version
87
+ version: '0'
88
+ requirements: []
89
+ rubygems_version: 3.5.11
90
+ signing_key:
91
+ specification_version: 4
92
+ summary: An OmniAuth strategy for the Threads API
93
+ test_files: []