Skip to content

cadenza-tech/omniauth-qiita-v2

Repository files navigation

OmniauthQiitaV2

License Tag Release Test Lint

Qiita strategy for OmniAuth.

Installation

Install the gem and add to the application's Gemfile by executing:

bundle add omniauth-qiita-v2

If bundler is not being used to manage dependencies, install the gem by executing:

gem install omniauth-qiita-v2

Usage

Rails Configuration with Devise

Add the following to config/initializers/devise.rb:

# config/initializers/devise.rb
Devise.setup do |config|
  config.omniauth :qiita_v2, ENV['QIITA_CLIENT_ID'], ENV['QIITA_CLIENT_SECRET']
end

Add the OmniAuth callbacks routes to config/routes.rb:

# config/routes.rb
Rails.application.routes.draw do
  devise_for :users, controllers: { omniauth_callbacks: 'users/omniauth_callbacks' }
end

Add the OmniAuth configuration to your Devise model:

class User < ApplicationRecord
  devise :database_authenticatable, :registerable,
         :recoverable, :rememberable, :validatable,
         :omniauthable, omniauth_providers: [:qiita_v2]
end

Configuration Options

You can configure several options:

# config/initializers/devise.rb
Devise.setup do |config|
  config.omniauth :qiita_v2, ENV['QIITA_CLIENT_ID'], ENV['QIITA_CLIENT_SECRET'],
    {
      scope: 'read_qiita write_qiita', # Specify OAuth scopes
      callback_path: '/custom/qiita_v2/callback' # Custom callback path
    }
end

Available scopes:

  • read_qiita - Access to read data from Qiita
  • write_qiita - Access to write data to Qiita

Auth Hash

After successful authentication, the auth hash will be available in request.env['omniauth.auth']:

{
  provider: 'qiita_v2',
  uid: 'qiita',
  info: {
    name: 'Qiita キータ',
    nickname: 'qiita',
    image: 'https://s3-ap-northeast-1.amazonaws.com/qiita-image-store/0/88/ccf90b557a406157dbb9d2d7e543dae384dbb561/large.png?1575443439',
    description: 'Hello, world.',
    location: 'Tokyo, Japan',
    urls: {
      website: 'https://qiita.com',
      x: 'https://x.com/qiita',
      twitter: 'https://twitter.com/qiita',
      facebook: 'https://facebook.com/qiita',
      linkedin: 'https://www.linkedin.com/in/qiita',
      github: 'https://github.com/qiitan'
    }
  },
  credentials: {
    token: 'access_token_here',
    expires: false
  },
  extra: {
    raw_info: {
      'description' => 'Hello, world.',
      'facebook_id' => 'qiita',
      'followees_count' => 100,
      'followers_count' => 200,
      'github_login_name' => 'qiitan',
      'id' => 'qiita',
      'items_count' => 300,
      'linkedin_id' => 'qiita',
      'location' => 'Tokyo, Japan',
      'name' => 'Qiita キータ',
      'organization' => 'Qiita Inc.',
      'permanent_id' => 1,
      'profile_image_url' => 'https://s3-ap-northeast-1.amazonaws.com/qiita-image-store/0/88/ccf90b557a406157dbb9d2d7e543dae384dbb561/large.png?1575443439',
      'team_only' => false,
      'twitter_screen_name' => 'qiita',
      'website_url' => 'https://qiita.com',
      'image_monthly_upload_limit' => 1048576,
      'image_monthly_upload_remaining' => 524288
    }
  }
}

Changelog

See CHANGELOG.md.

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/cadenza-tech/omniauth-qiita-v2. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the code of conduct.

License

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

Code of Conduct

Everyone interacting in the OmniauthQiitaV2 project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the code of conduct.

Sponsor

You can sponsor this project on Patreon.

About

Qiita strategy for OmniAuth.

Topics

Resources

License

Code of conduct

Stars

Watchers

Forks

Sponsor this project