Git Product home page Git Product logo

omniauth-vatsim's Introduction

OmniAuth VATSIM

OmniAuth::Strategies::Vatsim is an OmniAuth strategy for authenticating with the VATSIM SSO with OAuth1.

Installation

Add this line to your application's Gemfile:

gem 'omniauth-vatsim'

And then execute:

$ bundle

Or install it yourself as:

$ gem install omniauth-vatsim

Usage

Add the strategy to your Gemfile:

gem 'omniauth-vatsim'

Or you can pull it directly from github:

gem 'omniauth-vatsim', git: 'https://github.com/jvoss/omniauth-vatsim.git'

RSA-SHA1 (Recommended)

IMPORTANT NOTE

An issue with OAuth-Ruby v0.5.1 requires the consumer secret to be set with RSA-SHA1. Unfortunately that means it must be set to the contents of an unencrypted (no passphrase) private key file! In my examples below, I suggest a way to do this in memory while still keeping a passphrase on the key.

Specifically the issue lies here at line 37. It does not matter if a private key is specified in the consumer, it always will instantiate a new private key object.

For a Rails application, create an initializer config/initializers/omniauth.rb:

Rails.application.config.middleware.use OmniAuth::Builder do
  private_key = OpenSSL::PKey::RSA.new(IO.read('<PRIVATE KEY FILENAME>'), ENV['key_passphrase'])

  provider :vatsim, 'Consumer Key', private_key.to_pem, 
     site: 'https://cert.vatsim.net/sso',
     signature_method: 'RSA-SHA1',
     private_key: private_key
end

For a Rails application using Devise, modify config/initializers/devise.rb:

private_key = OpenSSL::PKey::RSA.new(IO.read('<PRIVATE KEY FILENAME>'), ENV['key_passphrase'])

config.omniauth :vatsim, 'Consumer Key', private_key, 
  client_options: {
    site: 'https://cert.vatsim.net/sso',
    signature_method: 'RSA-SHA1',
    private_key: private_key
  }

For Sinatra you would add:

use Rack::Session::Cookie

private_key = OpenSSL::PKey::RSA.new(IO.read('<PRIVATE KEY FILENAME>'), ENV['key_passphrase'])

use OmniAuth::Builder do
  provider :vatsim, 'Consumer Key', private_key, 
    site: 'https://cert.vatsim.net/sso'
    signature_method: 'RSA-SHA1',
    private_key: private_key
end

HMAC-SHA1

For a Rails application, create an initializer config/initializers/omniauth.rb:

Rails.application.config.middleware.use OmniAuth::Builder do
  provider :vatsim, 'Consumer Key', 'Consumer Secret', site: 'https://cert.vatsim.net/sso'
end

For a Rails application using Devise, modify config/initializers/devise.rb:

config.omniauth :vatsim, 'Consumer Key', 'Consumer Secret', client_options: {site: 'https://cert.vatsim.net/sso'}

For Sinatra you would add:

use Rack::Session::Cookie
use OmniAuth::Builder do
  provider :vatsim, 'Consumer Key', 'Consumer Secret', site: 'https://cert.vatsim.net/sso'
end

Sample Auth Hash

{
  "provider"=>"vatsim",
  "uid"=>"1300011",
  "info"=>{
    "id"=>"1300011",
    "name_first"=>"11th",
    "name_last"=>"Test",
    "rating"=>{
      "id"=>"11", 
      "short"=>"SUP", 
      "long"=>"Supervisor", 
      "GRP"=>"Supervisor"
    },
    "pilot_rating"=>{
      "rating"=>"22",
      "2"=>{
        "id"=>2, 
        "short"=>"P2", 
        "long"=>"Flight Fundamentals"
      },
      "4"=>{
        "id"=>4,
        "short"=>"P3",
        "long"=>"VFR Pilot"
      },
      "16"=>{
        "id"=>16, 
        "short"=>"P5", 
        "long"=>"Advanced IFR Pilot"
       }
     },
     "email"=>"[email protected]",
     "experience"=>"N",
     "reg_date"=>"2014-05-14 17:17:26",
     "country"=>{
       "code"=>"GB", "name"=>"United Kingdom"
     },
     "region"=>{
       "code"=>"EUR", "name"=>"Europe"
     },
     "division"=>{
       "code"=>"GBR", "name"=>"United Kingdom"
     },
     "subdivision"=>{
       "code"=>nil, "name"=>nil
     }
   }

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/jvoss/omniauth-vatsim.

License

The gem is available as open source under the terms of the MIT License.

omniauth-vatsim's People

Contributors

jvoss avatar

Watchers

 avatar

Forkers

mkosmo

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.