Skip to content

Zip753/rails_sso

This branch is 1 commit ahead of monterail/rails_sso:master.

Folders and files

NameName
Last commit message
Last commit date

Latest commit

00ff449 · Feb 12, 2017

History

81 Commits
Sep 11, 2015
Sep 11, 2015
Feb 12, 2017
Mar 17, 2016
Feb 23, 2015
Mar 17, 2016
Feb 17, 2015
Jan 14, 2015
Aug 26, 2015
Jan 15, 2015
Mar 10, 2015
Jan 21, 2016

Repository files navigation

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

About

Single Sign On solution for Ruby on Rails

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Ruby 86.5%
  • HTML 10.7%
  • CSS 1.5%
  • JavaScript 1.3%