Giter Site home page Giter Site logo

signonotron2's Introduction

Signon

This is a centralised OAuth 2-based single sign-on provider for GDS services.

We use Devise to provide username / password sign-in, and Doorkeeper to provide an OAuth 2 provider.

Details of our interpretation of OAuth are provided in an accompanying document

Usage

The application has Rake tasks to create new users and client applications.

To create a new client application to which Signon will provide sign-on services:

rake applications:create name=ClientName description="What does this app do" \
home_uri="https://myapp.com" redirect_uri="https://myapp.com/auth/gds/callback"

This will create and return a client ID and secret that can be used in the app (normally via GDS-SSO).

You can then add the ID and secret to the app's ENV using your preferred method.

To create a new user, use the following syntax:

rake users:create name='First Last' [email protected] \
applications=Comma,Seperated,ListOf,Application,Names* \
[github=username] [twitter=username]

* You can also set the applications in a comma separated list via an ENV['APPLICATIONS'] variable if you prefer.

You may also need to create an API client, so one application can identify itself to another. Say, for instance, you have an API that requires authentication and you need to configure a frontend to make requests of it. Assuming you have your application set up in Signon under the name "Stuff API", follow these steps to create an access token for API clients to access your application:

  • Login to Signon with 'superadmin' role
  • Click 'API Users', followed by 'Create API User'
  • Fill-in a name and email for the API client
  • Once saved, click "Add application token", select "Stuff API" and press "Create access token"
  • You should see an access token on the screen, which you must copy as it is the only time it'll be displayed on screen.

Getting this working in development.

More detail is contained in the GDS-SSO Repo, but if you just want to get this working, follow the steps below:

  • If you haven't already set real tokens in your app's ENV, you'll first need to run the following command to make sure your database has got OAuth config that matches what the apps use in development mode:

    bundle exec ./script/make_oauth_work_in_dev
    
  • You must then make sure you set an environment variable when you run your app. eg:

    GDS_SSO_STRATEGY=real bundle exec rails s
    

Creating new permissions

To create a new permission for an existing app, you first need to have the "superadmin" role on your account (or have access to someone who does): you'll then be able to access the "Administer applications" menu item. Under the application you want to change, follow the "Supported Permissions" link and add a new permission from there.

Note that this UI won't let you edit or delete existing permissions.

Running the Application

The web application itself is run like any other Rails app, for example:

script/rails s

In development, you can run sidekiq to process background jobs:

bundle exec sidekiq -C config/sidekiq.yml

Implementation Notes

The application is divided into two parts: user management (User sign-on and passwords) and OAuth delegation (SSO service, contacts API).

User management is handled by Devise. Configuration is in config/initializers/devise and views are either concrete (under app/views/devise) or pulled in from the Devise gem. Likewise with Controllers, though Devise controllers should inherit from Devise::SomeController (e.g., as with the PasswordsController).

API authentication is handled by Doorkeeper. It's a bit of a tricky beast, but not too bad overall, and it nicely separates concerns. Instead of exposing the current user with current_user, Doorkeeper exposes the current valid OAuth token as doorkeeper_token. Doorkeeper tokens are associated with a resource owner through an authenticator block, defined in config/initializers/doorkeeper.

To require Devise authentication in a controller (ie, you want a user sitting at a computer looking at the page), add before_filter:authenticate_user! to the controller.

For example:

class SettingsController
  before_filter :authenticate_user!

  def show
    settings = current_user.settings
  end
end

To require Doorkeeper authentication in a controller (i.e., you want an application that has been granted a token on behalf of a user to interact with the controller), add before_filter :doorkeeper_authorize! to the controller.

For example:

class AutomaticApiController
  before_filter :doorkeeper_authorize!

  def swizzle
    @token_owning_user = User.find_by_id(doorkeeper_token.resource_owner_id)
  end
end

signonotron2's People

Contributors

jamiecobbett avatar alext avatar benilovj avatar boffbowsh avatar benlovell avatar fofr avatar bishboria avatar jystewart avatar blaine avatar dhwthompson avatar vinayvinay avatar jennyd avatar mnowster avatar heathd avatar jordanhatch avatar partiallyblind avatar bradwright avatar tijmenb avatar steventux avatar matthewford avatar jabley avatar elliotcm avatar evilstreak avatar davidillsley avatar danielroseman avatar john-griffin avatar kushalp avatar marksheldongds avatar philandstuff avatar pezholio avatar

Watchers

Tadas Tamošauskas avatar James Cloos avatar  avatar

Forkers

coke-zero

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.