SSO client Rails Engine
About
SOON
Installation
Add engine and omniauth provider gems to your project:
# Gemfile
gem 'omniauth-example'
gem 'rails_sso'
Install initializer and mount routes:
bin/rails generate rails_sso
Configure initializer:
# conifg/initializers/sso.rb
RailsSso.configure do |config|
# include RailsSso::Helpers to ActionController::Base
config.magic_enabled = true
# url of entity provider
config.provider_url = 'https://example.com'
# name of oauth2 provider
config.provider_name = 'example'
# oauth keys for omniauth-example
config.provider_key = ENV['PROVIDER_KEY']
config.provider_secret = ENV['PROVIDER_SECRET']
# path for fetching user data
config.provider_profile_path = '/api/v1/profile'
# set if you support single sign out
config.provider_sign_out_path = '/api/v1/session'
# enable cache (will use Rails.cache store)
config.use_cache = Rails.application.config.action_controller.perform_caching
# test & development mode
config.test_mode = ENV['mock_sso']
config.access_token_mock = ENV['access_token_mock']
config.profile_mocks = {
'169783' => {
user: 'John Blacksmith',
uid: '169783'
}
}
# custom failure app
# more: https://github.com/hassox/warden/wiki/Failures
config.failure_app = MyFailureApp
end
And mount it:
# config/routes.rb
Rails.application.routes.draw do
mount RailsSso::Engine => '/sso', as: 'sso'
end
Usage
Include helpers to your controller if you disabled auto include:
class ApplicationController < ActionController::Base
include RailsSso::Helpers
end
Available helpers for controllers and views:
current_user_data
user_signed_in?
Available filters and helpers for controllers:
authenticate_user!
sign_in_with_access_token!(access_token)
sign_out!
warden
sso_app
Available helpers for views:
sso.sign_in_path
sso.sign_out_path
Testing & Development mode
You can turn on "test mode" by enabling test mode. It will also automatically enable OmniAuth test mode.
RailsSso.configure do
config.test_mode = true
end
Mock data should be passed to profile_mocks
configuration with dummy access token as a key.
RailsSso.configure do |config|
config.profile_mocks = {
"kowalski_uid" => {
"name" => "John Kowalski",
"uid" => "42"
},
"nowak_uid" => {
"name" => "Pawel Nowak",
"uid" => "23"
}
}
end
Finally you have to select which token to use.
RailsSso.configure do |config|
config.access_token_mock = "kowalski_uid"
end
To mock signed out state set nil
to access token value.
Contributing
- Fork it
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create new Pull Request