Project

rails_sso

0.01
Repository is archived
No commit activity in last 3 years
No release in over 3 years
There's a lot of open issues
Single Sign On solution via OAuth2 for Ruby on Rails.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

>= 0
>= 0
>= 0

Runtime

< 1.4, ~> 1.2
~> 4.1
~> 1.2
 Project Readme

SSO client Rails Engine

Join the chat at https://gitter.im/monterail/rails_sso

Circle CI Dependency Status Gem Version Code Climate Test Coverage

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

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request