OmniauthQiitaV2
Qiita strategy for OmniAuth.
- Installation
- Usage
- Rails Configuration with Devise
- Configuration Options
- Auth Hash
- Changelog
- Contributing
- License
- Code of Conduct
- Sponsor
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: %i[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: 'example_qiita_user_john_doe',
info: {
name: 'John Doe',
nickname: 'example_qiita_user_john_doe',
permanent_id: 1234567890,
image: 'https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/...',
description: 'Software Developer',
location: 'Tokyo, Japan',
organization: 'Example Inc.',
followees_count: 50,
followers_count: 100,
items_count: 30,
urls: {
website: 'https://example.com',
twitter: 'https://x.com/...',
facebook: 'https://facebook.com/...',
linkedin: 'https://www.linkedin.com/in/...',
github: 'https://github.com/...'
}
},
credentials: {
token: 'access_token_here',
expires: false
},
extra: {
raw_info: {
# Complete user information from Qiita API
}
}
}
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.