OmniAuth Classiclaw Data Platform OAuth2

数据生产平台OAuth授权

Installing

Add to your Gemfile:

gem 'omniauth-classiclaw-oauth2', git: 'ssh://[email protected]:2020/data_platform/omniauth-classiclaw-oauth2.git'

Then bundle install

Usage

OmniAuth::Strategies::Classiclaw is simply a Rack middleware. Read the OmniAuth 1.0 docs for detailed instructions: https://github.com/intridea/omniauth.

Here's a quick example, adding the middleware to a Rails app in config/initializers/omniauth.rb:

Rails.application.config.middleware.use OmniAuth::Builder do
  provider :classiclaw, ENV['PLATFORM_APPID'], ENV['PLATFORM_SECRET'], client_options: {
    site: ENV['PLATFORM_URL']
  }
end

Configuration

you can set up redirect_uri in omniauth.rb as following:

provider :classiclaw, ENV['PLATFORM_APPID'], ENV['PLATFORM_SECRET'], client_options: {
  site: ENV['PLATFORM_URL']
}

Authentication Hash

{
  :provider => 'classiclaw',
  :uid => '1234567890',
  :info => {
    :name => '张三',
    :email => '[email protected]',
    :court_id => 215,
    :dlbs => 'tester',
    :rybs => 'tester'
  },
  :extra => {
    :raw_info => {
        'uid' => '1234567890',
       'name' => '张三',
       'court_id' => 215, # 默认曲阳县人民法院
       'dlbs' => 'tester',
       'rybs' => 'tester'
    }
  }
}

Rails

Add a callback route to config/routes.rb

get '/auth/:provider/callback', to: 'sessions#create'

Create the SessionsController

class SessionsController < ApplicationController
  def create
    @user = User(request.env['omniauth.auth'])
    session['current_user_id'] = @user.id
    redirect_to root_path
  end
end

For your views you can login using:

<%= link_to "Sign in with Data Platform", '/auth/classiclaw' %>

TODO

  1. get real user info and return to the Authentication Hash