omniauth-classiclaw-oauth2 0.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/MIT-LICENSE +0 -0
- data/README.md +88 -0
- data/Rakefile +0 -0
- data/lib/omniauth-classiclaw-oauth2.rb +1 -0
- data/lib/omniauth/classiclaw_oauth2.rb +1 -0
- data/lib/omniauth/classiclaw_oauth2/version.rb +5 -0
- data/lib/omniauth/strategies/classiclaw.rb +51 -0
- metadata +122 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 3d64f4ce42575c16f06c640802d12157f5fb8516
|
4
|
+
data.tar.gz: 8ae0d408afd6a33e8961668b401451a71b6221e0
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 148267d8c0ef8e83e17defea1ad1811b725a6f17ad29db123ebafef2616aebe2c49af2669217c7e5bf98ff0643f7acfc651d50a27d0a56eb35a1e0d2a597a4c6
|
7
|
+
data.tar.gz: eb249668a697cb06118c5af0cbf966678049e627b19106ec22dcc1600054faf577ee5f5fd27b7715970f47314ca81fc6a382298890f311f3403cb4004f172089
|
data/MIT-LICENSE
ADDED
File without changes
|
data/README.md
ADDED
@@ -0,0 +1,88 @@
|
|
1
|
+
# OmniAuth Classiclaw Data Platform OAuth2
|
2
|
+
数据生产平台OAuth授权
|
3
|
+
|
4
|
+
## Installing
|
5
|
+
|
6
|
+
Add to your Gemfile:
|
7
|
+
|
8
|
+
```
|
9
|
+
gem 'omniauth-classiclaw-oauth2', git: 'ssh://git@git.classiclaw.com:2020/data_platform/omniauth-classiclaw-oauth2.git'
|
10
|
+
```
|
11
|
+
Then `bundle install`
|
12
|
+
|
13
|
+
## Usage
|
14
|
+
|
15
|
+
OmniAuth::Strategies::Classiclaw is simply a Rack middleware. Read the OmniAuth 1.0 docs for detailed instructions: https://github.com/intridea/omniauth.
|
16
|
+
|
17
|
+
Here's a quick example, adding the middleware to a Rails app in `config/initializers/omniauth.rb`:
|
18
|
+
|
19
|
+
```
|
20
|
+
Rails.application.config.middleware.use OmniAuth::Builder do
|
21
|
+
provider :classiclaw, ENV['PLATFORM_APPID'], ENV['PLATFORM_SECRET'], client_options: {
|
22
|
+
site: ENV['PLATFORM_URL']
|
23
|
+
}
|
24
|
+
end
|
25
|
+
```
|
26
|
+
|
27
|
+
## Configuration
|
28
|
+
|
29
|
+
you can set up redirect_uri in omniauth.rb as following:
|
30
|
+
|
31
|
+
```
|
32
|
+
provider :classiclaw, ENV['PLATFORM_APPID'], ENV['PLATFORM_SECRET'], client_options: {
|
33
|
+
site: ENV['PLATFORM_URL']
|
34
|
+
}
|
35
|
+
```
|
36
|
+
|
37
|
+
## Authentication Hash
|
38
|
+
```
|
39
|
+
{
|
40
|
+
:provider => 'classiclaw',
|
41
|
+
:uid => '1234567890',
|
42
|
+
:info => {
|
43
|
+
:name => '张三',
|
44
|
+
:email => 'tester@t.com',
|
45
|
+
:court_id => 215,
|
46
|
+
:dlbs => 'tester',
|
47
|
+
:rybs => 'tester'
|
48
|
+
},
|
49
|
+
:extra => {
|
50
|
+
:raw_info => {
|
51
|
+
'uid' => '1234567890',
|
52
|
+
'name' => '张三',
|
53
|
+
'court_id' => 215, # 默认曲阳县人民法院
|
54
|
+
'dlbs' => 'tester',
|
55
|
+
'rybs' => 'tester'
|
56
|
+
}
|
57
|
+
}
|
58
|
+
}
|
59
|
+
```
|
60
|
+
|
61
|
+
## Rails
|
62
|
+
|
63
|
+
Add a callback route to `config/routes.rb`
|
64
|
+
|
65
|
+
```
|
66
|
+
get '/auth/:provider/callback', to: 'sessions#create'
|
67
|
+
```
|
68
|
+
|
69
|
+
Create the `SessionsController`
|
70
|
+
|
71
|
+
```
|
72
|
+
class SessionsController < ApplicationController
|
73
|
+
def create
|
74
|
+
@user = User(request.env['omniauth.auth'])
|
75
|
+
session['current_user_id'] = @user.id
|
76
|
+
redirect_to root_path
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
```
|
81
|
+
|
82
|
+
For your views you can login using:
|
83
|
+
|
84
|
+
`<%= link_to "Sign in with Data Platform", '/auth/classiclaw' %>`
|
85
|
+
|
86
|
+
## TODO
|
87
|
+
1. get real user info and return to the Authentication Hash
|
88
|
+
|
data/Rakefile
ADDED
File without changes
|
@@ -0,0 +1 @@
|
|
1
|
+
require 'omniauth/classiclaw_oauth2'
|
@@ -0,0 +1 @@
|
|
1
|
+
require 'omniauth/strategies/classiclaw'
|
@@ -0,0 +1,51 @@
|
|
1
|
+
require 'omniauth/strategies/oauth2'
|
2
|
+
|
3
|
+
module OmniAuth
|
4
|
+
module Strategies
|
5
|
+
class Classiclaw < OmniAuth::Strategies::OAuth2
|
6
|
+
# Give your strategy a name.
|
7
|
+
option :name, "classiclaw"
|
8
|
+
|
9
|
+
# This is where you pass the options you would pass when
|
10
|
+
# initializing your consumer from the OAuth gem.
|
11
|
+
option :client_options, {:site => "http://122.112.18.6:33000"}
|
12
|
+
|
13
|
+
# These are called after authentication has succeeded. If
|
14
|
+
# possible, you should try to set the UID without making
|
15
|
+
# additional calls (if the user id is returned with the token
|
16
|
+
# or as a URI parameter). This may not be possible with all
|
17
|
+
# providers.
|
18
|
+
uid{ raw_info['uid'] }
|
19
|
+
|
20
|
+
info do
|
21
|
+
{
|
22
|
+
:name => raw_info['name'],
|
23
|
+
:email => raw_info['email'],
|
24
|
+
:court_id => raw_info['court_id'],
|
25
|
+
:courtroom_id => raw_info['courtroom_id'],
|
26
|
+
:dlbs => raw_info['dlbs'],
|
27
|
+
:rybs => raw_info['rybs']
|
28
|
+
}
|
29
|
+
end
|
30
|
+
|
31
|
+
extra do
|
32
|
+
{
|
33
|
+
'raw_info' => raw_info
|
34
|
+
}
|
35
|
+
end
|
36
|
+
|
37
|
+
def raw_info
|
38
|
+
@raw_info ||= access_token.get('/api/v1/profile.json').parsed
|
39
|
+
token_params = access_token.params
|
40
|
+
@raw_info.merge({
|
41
|
+
'uid' => token_params['uid'],
|
42
|
+
'name' => token_params['realname'],
|
43
|
+
'court_id' => token_params['court_id'],
|
44
|
+
'courtroom_id' => token_params['courtroom_id'],
|
45
|
+
'dlbs' => token_params['dlbs'],
|
46
|
+
'rybs' => token_params['rybs']
|
47
|
+
})
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
metadata
ADDED
@@ -0,0 +1,122 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: omniauth-classiclaw-oauth2
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.2.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Shuaifeng Xin
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2019-07-30 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: omniauth
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 1.1.1
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 1.1.1
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: omniauth-oauth2
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.5'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.5'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '12.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '12.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rspec
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '3.6'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '3.6'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: settingslogic
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '2.0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '2.0'
|
83
|
+
description: A Classiclaw OAuth2 strategy for OmniAuth 1.x. This allows you to login
|
84
|
+
to Classiclaw with your ruby app.
|
85
|
+
email:
|
86
|
+
- shuaifeng.xin@classiclaw.com
|
87
|
+
executables: []
|
88
|
+
extensions: []
|
89
|
+
extra_rdoc_files: []
|
90
|
+
files:
|
91
|
+
- MIT-LICENSE
|
92
|
+
- README.md
|
93
|
+
- Rakefile
|
94
|
+
- lib/omniauth-classiclaw-oauth2.rb
|
95
|
+
- lib/omniauth/classiclaw_oauth2.rb
|
96
|
+
- lib/omniauth/classiclaw_oauth2/version.rb
|
97
|
+
- lib/omniauth/strategies/classiclaw.rb
|
98
|
+
homepage: http://www.classiclaw.com/
|
99
|
+
licenses:
|
100
|
+
- MIT
|
101
|
+
metadata: {}
|
102
|
+
post_install_message:
|
103
|
+
rdoc_options: []
|
104
|
+
require_paths:
|
105
|
+
- lib
|
106
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '2.1'
|
111
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
112
|
+
requirements:
|
113
|
+
- - ">="
|
114
|
+
- !ruby/object:Gem::Version
|
115
|
+
version: '0'
|
116
|
+
requirements: []
|
117
|
+
rubyforge_project:
|
118
|
+
rubygems_version: 2.5.1
|
119
|
+
signing_key:
|
120
|
+
specification_version: 4
|
121
|
+
summary: A Classiclaw OAuth2 strategy for OmniAuth 1.x
|
122
|
+
test_files: []
|