Unofficial OmniAuth strategy to authenticate with Rocket Chat through OAuth2 in OmniAuth.
Add this line to your application's Gemfile:
gem 'omniauth-rocketchat'
Then execute bundle install
.
You need to register your application with your Rocket Chat instance to obtain the Client ID
and Client Secret
. You will also need to add this applications host(s). This whitelists your application for the callback redirect. You can do this by following the steps below:
- Go to your Rocket Chat instance and login as an administrator.
- Go to
Administration
->Third-party login
. - Click on
New Application
.- Check the
Active
checkbox. - Fill in the
Application Name
andRedirect URL
. The redirect URL for devise looks likehttps://example.com/users/auth/rocketchat/callback
. You can add multiple hosts by separating them with a comma. - Click on
Save
.
- Check the
- Select the third-party login you just created.
- Copy the
Client ID
andClient Secret
.
- Copy the
Pick one of the following methods to integrate the strategy with your application.
use OmniAuth::Builder do
provider :rocketchat,
ENV["ROCKETCHAT_CLIENT_ID"],
ENV["ROCKETCHAT_CLIENT_SECRET"],
client_options: {
site: "https://example.com"
}
end
use OmniAuth::Builder do
provider :rocketchat,
ENV["ROCKETCHAT_CLIENT_ID"],
ENV["ROCKETCHAT_CLIENT_SECRET"],
client_options: {
site: "https://example.com",
authorize_url: "/custom/oauth/authorize",
token_url: "/custom/oauth/token"
}
end
# config/initializers/rocketchat.rb
Rails.application.config.middleware.use OmniAuth::Builder do
provider :rocketchat,
ENV["ROCKETCHAT_CLIENT_ID"],
ENV["ROCKETCHAT_CLIENT_SECRET"],
client_options: {
site: "https://example.com"
}
end
# config/initializers/rocketchat.rb
Devise.setup do |config|
config.omniauth :rocketchat,
ENV["ROCKETCHAT_CLIENT_ID"],
ENV["ROCKETCHAT_CLIENT_SECRET"],
client_options: {
site: "https://example.com"
}
end
- The
client_options
options:authorize_url
andtoken_url
are optional and default to/oauth/authorize
and/oauth/token
respectively. scope
has no effect on Rocket Chat. Users grant you full permissions to their account. Handle responsibly!
This library aims to adhere to Semantic Versioning 2.0.0. Violations of this scheme should be reported as bugs.
This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the Contributor Covenant code of conduct.
Bug reports and pull requests are welcome on the GitHub project page.
Copyright © 2024 David Uhlig. See LICENSE for details.