omniauth-centralid 1.2.0 → 1.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/README.md +19 -10
- data/lib/omniauth/strategies/centralid.rb +9 -9
- data/lib/omniauth-centralid/version.rb +1 -1
- metadata +6 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: '08637c544cff96c710495dfe33f1a8b1dc8518c06a8182de104f4dc091c0662a'
|
4
|
+
data.tar.gz: 004c208ca78837a67a400a7383120ec272e41dc52d73d35cdde81282bc82755e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a8fc89ad1a51cb4175146f23e028943cb0a99bc892c5d30f081e64979462ef52fc11ba919c3f9f3e9da161faf44e95bcd0c84b1b7450326aa5ee177ee71912d4
|
7
|
+
data.tar.gz: bde115d788db34b4f28485fe7711741a2f7fc3e20e7523d02d26449286cb409098cb12666250586f4e17c48b2cec638dd4f5da1852aedcdfacbb3cddcf28bf16
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -8,21 +8,30 @@ This gem offers OmniAuth strategy for Central ID service.
|
|
8
8
|
First start by adding this gem to your Gemfile:
|
9
9
|
|
10
10
|
```ruby
|
11
|
-
gem
|
11
|
+
gem "omniauth-centralid"
|
12
12
|
```
|
13
13
|
|
14
|
-
Next,
|
14
|
+
Next, let OmniAuth know about provider. In a Rails app, create an initializer for instance `config/initializers/omniauth.rb` with:
|
15
15
|
|
16
16
|
```ruby
|
17
17
|
Rails.application.config.middleware.use OmniAuth::Builder do
|
18
18
|
provider :centralid, "CENTRALID_KEY", "CENTRALID_SECRET"
|
19
19
|
end
|
20
20
|
```
|
21
|
+
You can override config, like
|
22
|
+
```ruby
|
23
|
+
Rails.application.config.middleware.use OmniAuth::Builder do
|
24
|
+
provider :centralid, "CENTRALID_KEY", "CENTRALID_SECRET",
|
25
|
+
client_options: {
|
26
|
+
site: "http://localhost:3000"
|
27
|
+
}
|
28
|
+
end
|
29
|
+
```
|
21
30
|
In your routes file:
|
22
31
|
|
23
32
|
```ruby
|
24
|
-
get
|
25
|
-
get
|
33
|
+
get "auth/:provider/callback", to: "oauths#create"
|
34
|
+
get "auth/failure", to: "oauths#failure" # optional (to override default redirect behaviour)
|
26
35
|
```
|
27
36
|
|
28
37
|
Add a controller (oauths_controller.rb as defined in your routes)
|
@@ -31,8 +40,8 @@ Add a controller (oauths_controller.rb as defined in your routes)
|
|
31
40
|
# sends the user on a trip to the provider,
|
32
41
|
# and after authorizing there back to the callback url.
|
33
42
|
def create
|
34
|
-
auth = request.env[
|
35
|
-
user = User.find_by(provider: auth[
|
43
|
+
auth = request.env["omniauth.auth"]
|
44
|
+
user = User.find_by(provider: auth["provider"], uid: auth["uid"]).try(:user) || User.create_with_omniauth(auth)
|
36
45
|
# Sign in the user
|
37
46
|
session[:user_id] = user.id
|
38
47
|
redirect_to dashboard_path
|
@@ -52,12 +61,12 @@ And finally add a `create_with_omniauth` method in your user model.
|
|
52
61
|
|
53
62
|
def self.create_with_omniauth(auth)
|
54
63
|
user = create! do |user|
|
55
|
-
user.full_name = auth[
|
56
|
-
user.email = auth[
|
64
|
+
user.full_name = auth["info"]["name"]
|
65
|
+
user.email = auth["info"]["email"]
|
57
66
|
user.password = SecureRandom.hex
|
58
67
|
user.authentications.new(
|
59
|
-
provider: auth[
|
60
|
-
uid: auth[
|
68
|
+
provider: auth["provider"],
|
69
|
+
uid: auth["uid"]
|
61
70
|
)
|
62
71
|
end
|
63
72
|
user
|
@@ -1,5 +1,5 @@
|
|
1
|
-
require
|
2
|
-
require
|
1
|
+
require "omniauth-oauth2"
|
2
|
+
require "multi_json"
|
3
3
|
|
4
4
|
module OmniAuth
|
5
5
|
module Strategies
|
@@ -7,26 +7,26 @@ module OmniAuth
|
|
7
7
|
option :name, :centralid
|
8
8
|
|
9
9
|
option :client_options, {
|
10
|
-
site:
|
11
|
-
authorize_path:
|
10
|
+
site: "https://centralid.yafoy.com",
|
11
|
+
authorize_path: "/oauth/authorize"
|
12
12
|
}
|
13
13
|
|
14
14
|
option :fields, [:name, :email]
|
15
15
|
|
16
16
|
uid do
|
17
|
-
raw_info[
|
17
|
+
raw_info["id"]
|
18
18
|
end
|
19
19
|
|
20
20
|
info do
|
21
21
|
{
|
22
|
-
name: raw_info[
|
23
|
-
email: raw_info[
|
24
|
-
username: raw_info[
|
22
|
+
name: raw_info["full_name"],
|
23
|
+
email: raw_info["email"],
|
24
|
+
username: raw_info["username"]
|
25
25
|
}
|
26
26
|
end
|
27
27
|
|
28
28
|
def raw_info
|
29
|
-
@raw_info ||= access_token.get(
|
29
|
+
@raw_info ||= access_token.get("/api/v1/me").parsed
|
30
30
|
end
|
31
31
|
|
32
32
|
# https://github.com/intridea/omniauth-oauth2/issues/81
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: omniauth-centralid
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- yafoy
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-11-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: omniauth-oauth2
|
@@ -108,7 +108,7 @@ homepage: http://github.com/yafoy/omniauth-centralid
|
|
108
108
|
licenses:
|
109
109
|
- MIT
|
110
110
|
metadata: {}
|
111
|
-
post_install_message:
|
111
|
+
post_install_message:
|
112
112
|
rdoc_options: []
|
113
113
|
require_paths:
|
114
114
|
- lib
|
@@ -123,9 +123,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
123
123
|
- !ruby/object:Gem::Version
|
124
124
|
version: '0'
|
125
125
|
requirements: []
|
126
|
-
|
127
|
-
|
128
|
-
signing_key:
|
126
|
+
rubygems_version: 3.3.7
|
127
|
+
signing_key:
|
129
128
|
specification_version: 4
|
130
129
|
summary: Central ID stategy for OmniAuth
|
131
130
|
test_files: []
|