Skip to content

giacomoguiulfo/omniauth-threads-api

Repository files navigation

Omniauth::ThreadsAPI

Gem Version Build Status License

An OmniAuth strategy for authenticating with the Threads API via OAuth.

Installation

Add this line to your application's Gemfile:

gem 'omniauth-threads-api'

And then execute:

bundle install

Usage

Here's an example of using it in a Rails application:

# config/initializers/omniauth.rb
Rails.application.config.middleware.use OmniAuth::Builder do
  provider :threads, ENV['THREADS_CLIENT_ID'], ENV['THREADS_CLIENT_SECRET']
end

Make sure to set THREADS_CLIENT_ID and THREADS_CLIENT_SECRET environment variables to your actual credentials or use Rails encrypted credentials (e.g. Rails.application.credentials.threads).

Scopes

The default scope for this strategy is threads_basic. To add more scopes simply specify them after your credentials:

# config/initializers/omniauth.rb
Rails.application.config.middleware.use OmniAuth::Builder do
  provider :threads, ENV['THREADS_CLIENT_ID'], ENV['THREADS_CLIENT_SECRET'],
    scope: [
        'threads_basic',
        'threads_content_publish',
        'threads_read_replies',
        'threads_manage_replies',
        'threads_manage_insights',
    ].join(",")
end

Auth Hash

This is an example of what the Auth Hash available in request.env['omniauth.auth'] would look like:

{
  provider: 'threads',
  uid: '123456789',
  info: {
    name: 'John Doe',
    nickname: 'johndoe',
    description: "I'm just a tech",
    image: 'https://scontent-nrt1-1.cdninstagram.com/v/...',
  },
  credentials: {
    token: 'qwertyuiopasdfghjklzxcvbnm',
    expires: true,
    expires_at: 1733097115,
  },
  extra: {
    raw_info: {
      id: "123456789",
      name: "John Doe",
      username: "johndoe":
      threads_biography: "I'm just a tech",
      threads_profile_picture_url: "https://scontent-nrt1-1.cdninstagram.com/v/..."
    }
  }
}

The token stored in the credentials lasts for 60 days and can be refreshed.

License

The gem is available as open source under the terms of the MIT License.

About

An OmniAuth strategy for the Threads API

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published