Code Monkey home page Code Monkey logo

omniauth-jwt's Introduction

OmniAuth::JWT

Build Status

JSON Web Token (JWT) is a simple way to send verified information between two parties online. This can be useful as a mechanism for providing Single Sign-On (SSO) to an application by allowing an authentication server to send a validated claim and log the user in. This is how Zendesk does SSO, for example.

OmniAuth::JWT provides a clean, simple wrapper on top of JWT so that you can easily implement this kind of SSO either between your own applications or allow third parties to delegate authentication.

Installation

Add this line to your application's Gemfile:

gem 'omniauth-jwt'

And then execute:

$ bundle

Or install it yourself as:

$ gem install omniauth-jwt

Usage

You use OmniAuth::JWT just like you do any other OmniAuth strategy:

use OmniAuth::JWT, 'SHAREDSECRET', auth_url: 'http://example.com/login'

The first parameter is the shared secret that will be used by the external authenticator to verify that. You must also specify the auth_url option to tell the strategy where to redirect to log in. Other available options are:

  • algorithm: the algorithm to use to decode the JWT token. This is HS256 by default but can be set to anything supported by ruby-jwt
  • uid_claim: this determines which claim will be used to uniquely identify the user. Defaults to email
  • required_claims: array of claims that are required to make this a valid authentication call. Defaults to ['name', 'email']
  • info_map: array mapping claim values to info hash values. Defaults to mapping name and email to the same in the info hash.
  • valid_within: integer of how many seconds of time skew you will allow. Defaults to nil. If this is set, the iat claim becomes required and must be within the specified number of seconds of the current time. This helps to prevent replay attacks.

Authentication Process

When you authenticate through omniauth-jwt you can send users to /auth/jwt and it will redirect them to the URL specified in the auth_url option. From there, the provider must generate a JWT and send it to the /auth/jwt/callback URL as a "jwt" parameter:

/auth/jwt/callback?jwt=ENCODEDJWTGOESHERE

An example of how to do that in Sinatra:

require 'jwt'

get '/login/sso/other-app' do
  # assuming the user is already logged in and this is available as current_user
  claims = {
    id: current_user.id,
    name: current_user.name,
    email: current_user.email,
    iat: Time.now.to_i
  }
  
  payload = JWT.encode(claims, ENV['SSO_SECRET'])
  redirect "http://other-app.com/auth/jwt/callback?jwt=#{payload}"
end

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

omniauth-jwt's People

Contributors

mbleigh avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

omniauth-jwt's Issues

Security issue when include token in url

Correct me if I'm wrong, but is it unsecured to include the token in the redirection url? Any host standing in between may intercept and extract the token at will.

0.0.2 gem contains files with 0600 modes

$ curl -sO https://rubygems.org/downloads/omniauth-jwt-0.0.2.gem

$ gem unpack omniauth-jwt-0.0.2.gem
Unpacked gem: '/Users/richardc/src/omniauth-jwt-0.0.2'

$ find omniauth-jwt-0.0.2 -ls
8600003236        0 drwxr-xr-x   13 richardc         staff                 416 27 Mar 18:01 omniauth-jwt-0.0.2
8600003241        8 -rw-r--r--    1 richardc         staff                 236 27 Mar 18:01 omniauth-jwt-0.0.2/Guardfile
8600003238        8 -rw-rw-r--    1 richardc         staff                  26 27 Mar 18:01 omniauth-jwt-0.0.2/.rspec
8600003253        0 drwxr-xr-x    4 richardc         staff                 128 27 Mar 18:01 omniauth-jwt-0.0.2/spec
8600003258        8 -rw-rw-r--    1 richardc         staff                 906 27 Mar 18:01 omniauth-jwt-0.0.2/spec/spec_helper.rb
8600003254        0 drwxr-xr-x    3 richardc         staff                  96 27 Mar 18:01 omniauth-jwt-0.0.2/spec/lib
8600003255        0 drwxr-xr-x    3 richardc         staff                  96 27 Mar 18:01 omniauth-jwt-0.0.2/spec/lib/omniauth
8600003256        0 drwxr-xr-x    3 richardc         staff                  96 27 Mar 18:01 omniauth-jwt-0.0.2/spec/lib/omniauth/strategies
8600003257        8 -rw-------    1 richardc         staff                2423 27 Mar 18:01 omniauth-jwt-0.0.2/spec/lib/omniauth/strategies/jwt_spec.rb
8600003243        8 -rw-rw-r--    1 richardc         staff                3211 27 Mar 18:01 omniauth-jwt-0.0.2/README.md
8600003244        8 -rw-rw-r--    1 richardc         staff                 109 27 Mar 18:01 omniauth-jwt-0.0.2/Rakefile
8600003237        8 -rw-rw-r--    1 richardc         staff                 154 27 Mar 18:01 omniauth-jwt-0.0.2/.gitignore
8600003245        0 drwxr-xr-x    3 richardc         staff                  96 27 Mar 18:01 omniauth-jwt-0.0.2/lib
8600003246        0 drwxr-xr-x    5 richardc         staff                 160 27 Mar 18:01 omniauth-jwt-0.0.2/lib/omniauth
8600003248        0 drwxr-xr-x    3 richardc         staff                  96 27 Mar 18:01 omniauth-jwt-0.0.2/lib/omniauth/jwt
8600003249        8 -rw-rw-r--    1 richardc         staff                  61 27 Mar 18:01 omniauth-jwt-0.0.2/lib/omniauth/jwt/version.rb
8600003247        8 -rw-rw-r--    1 richardc         staff                  64 27 Mar 18:01 omniauth-jwt-0.0.2/lib/omniauth/jwt.rb
8600003250        0 drwxr-xr-x    3 richardc         staff                  96 27 Mar 18:01 omniauth-jwt-0.0.2/lib/omniauth/strategies
8600003251        8 -rw-------    1 richardc         staff                1552 27 Mar 18:01 omniauth-jwt-0.0.2/lib/omniauth/strategies/jwt.rb
8600003240        8 -rw-rw-r--    1 richardc         staff                  97 27 Mar 18:01 omniauth-jwt-0.0.2/Gemfile
8600003242        8 -rw-rw-r--    1 richardc         staff                1071 27 Mar 18:01 omniauth-jwt-0.0.2/LICENSE.txt
8600003239        8 -rw-rw-r--    1 richardc         staff                  63 27 Mar 18:01 omniauth-jwt-0.0.2/.travis.yml
8600003252        8 -rw-rw-r--    1 richardc         staff                1188 27 Mar 18:01 omniauth-jwt-0.0.2/omniauth-jwt.gemspec

The problematic file there is omniauth-jwt-0.0.2/lib/omniauth/strategies/jwt.rb. It's 0600 which means if I install it as a system gem only the user who installed it can use it.

Could you ship a 0.0.3 with that permission corrected? Thanks

Is JWKS public key supported?

Hello!
This omniauth strategy requires a secret to verify signature, but in my JWT setup (I use https://www.ory.sh/oathkeeper/docs/ ) I have JWT tokens which need to be verified with a published JWKS.json.

Is there a way to extract the shared secret from jwks.json, or are these two different, incompatible methods?

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.