Skip to content
morgz edited this page Sep 23, 2011 · 7 revisions

Welcome to the oauth-plugin wiki!

A few resources that you might find useful while developing with this plugin:

All 3 links contain small fixes I had to make to get this plugin to work correctly.

Setting up as a provider with a Sinatra consumer test app: https://github.com/Gazler/Oauth2-Tutorial

Another Provider tutorial: http://unhandledexpression.com/2011/06/02/rails-and-oauth-plugin-part-1-the-provider/

A consumer tutorial: http://unhandledexpression.com/2011/06/28/rails-and-oauth-plugin-part-2-the-consumer/

An Omniauth strategy for a provider made with this plugin: require 'omniauth/oauth' require 'multi_json'

module OmniAuth
  module Strategies
    class Active < OAuth2
      def initialize(app, client_id = nil, client_secret = nil, options = {}, &block)
        client_options = {
          :site => 'http://localhost:3000',
          :authorize_path => '/oauth/authorize',
          :access_token_path => '/oauth/access_token'
        }

        super(app, :active, client_id, client_secret, client_options, options, &block)
      end

      protected
      
      #customize this to return data on the user whose just logged in.
      def user_data
          @data ||= MultiJson.decode(@access_token.get('/users/1.json'))['user']
      end

      def auth_hash
        OmniAuth::Utils.deep_merge(super, {
          'uid' => user_data['id'],
          'extra' => {'user_hash' => user_data}
        })
      end
  
    end

  end

end
Clone this wiki locally