voxmedia/omniauth-oauth2

Name: omniauth-oauth2

Owner: Vox Media

Description: An abstract OAuth2 strategy for OmniAuth.

Forked from: omniauth/omniauth-oauth2

Created: 2017-10-23 20:04:44.0

Updated: 2017-10-23 20:04:46.0

Pushed: 2017-10-25 13:13:06.0

Homepage:

Size: 85

Language: Ruby

GitHub Committers

UserMost Recent Commit# Commits

Other Committers

UserEmailMost Recent Commit# Commits

README

OmniAuth OAuth2

Gem Version Build Status Dependency Status Code Climate Coverage Status

This gem contains a generic OAuth2 strategy for OmniAuth. It is meant to serve as a building block strategy for other strategies and not to be used independently (since it has no inherent way to gather uid and user info).

Creating an OAuth2 Strategy

To create an OmniAuth OAuth2 strategy using this gem, you can simply subclass it and add a few extra methods like so:

ire 'omniauth-oauth2'

le OmniAuth
dule Strategies
class SomeSite < OmniAuth::Strategies::OAuth2
  # Give your strategy a name.
  option :name, "some_site"

  # This is where you pass the options you would pass when
  # initializing your consumer from the OAuth gem.
  option :client_options, {:site => "https://api.somesite.com"}

  # These are called after authentication has succeeded. If
  # possible, you should try to set the UID without making
  # additional calls (if the user id is returned with the token
  # or as a URI parameter). This may not be possible with all
  # providers.
  uid{ raw_info['id'] }

  info do
    {
      :name => raw_info['name'],
      :email => raw_info['email']
    }
  end

  extra do
    {
      'raw_info' => raw_info
    }
  end

  def raw_info
    @raw_info ||= access_token.get('/me').parsed
  end
end
d

That's pretty much it!

Bitdeli Badge


This work is supported by the National Institutes of Health's National Center for Advancing Translational Sciences, Grant Number U24TR002306. This work is solely the responsibility of the creators and does not necessarily represent the official views of the National Institutes of Health.