omniauth-vis 0.1.0 → 0.1.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 +4 -4
- data/README.md +11 -16
- data/lib/omniauth/strategies/vis.rb +15 -1
- data/lib/vis/api.rb +3 -1
- data/omniauth-vis.gemspec +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7573bf727926ca641fcc5f511334866a3322f05774aa5fdfa6696aa8f1155bef
|
4
|
+
data.tar.gz: 31ef20a3225cc70cd7953784fb620f5362cebe84571063ae7f767f2bd4583cd0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4e13523d75a34af402b2be5efff2f626fbded669a06f663c4fa9a1aa23fc3c870d0142c84606f70839255ee72473805ce2526f2b11a27d96e273664371109c89
|
7
|
+
data.tar.gz: 1541a47d6a04a10114a7c3fc7d5a6023d42947a06fb1a16b582b54ccc291a9282b377a8d49b9efcd23aeb5539ee48656ed6a222b58ef5bafc9577853a5df58a4
|
data/README.md
CHANGED
@@ -12,31 +12,17 @@ Contact VIS administrators (sebastian.castro@dhamma.org, ryan.johnson@dhamma.org
|
|
12
12
|
|
13
13
|
- Name
|
14
14
|
- Home page url
|
15
|
-
- Logo url
|
16
15
|
- Authorized callback urls (example: https://myapp.org/users/auth/vis/callback)
|
17
16
|
|
18
17
|
## Install the gem
|
19
18
|
|
20
19
|
```
|
20
|
+
gem add omniauth
|
21
21
|
gem add omniauth-vis
|
22
22
|
```
|
23
23
|
|
24
|
-
## Configure
|
25
|
-
|
26
|
-
```
|
27
|
-
# config/initializers/vis.rb
|
28
|
-
|
29
|
-
Rails.application.config.vis = {
|
30
|
-
server_url: "https://identity.dhamma.org/"
|
31
|
-
app_id: "APP_ID_PROVIDED",
|
32
|
-
app_secret: "APP_SECRET_PROVIDED",
|
33
|
-
}
|
34
|
-
```
|
35
|
-
|
36
24
|
## Use omniauth strategy
|
37
25
|
|
38
|
-
You first need to install `omniauth-oauth2` gem, then add a new provider :
|
39
|
-
|
40
26
|
```
|
41
27
|
# config/initializers/omniauth.rb
|
42
28
|
|
@@ -47,6 +33,15 @@ Rails.application.config.middleware.use OmniAuth::Builder do
|
|
47
33
|
end
|
48
34
|
```
|
49
35
|
|
36
|
+
### Customize VIS server
|
37
|
+
|
38
|
+
In case you need to work with a custom server, for exmaple a staging server, you can use server_url option
|
39
|
+
```
|
40
|
+
provider :vis, Rails.application.config.vis["app_id"], Rails.application.config.vis["app_secret"], {
|
41
|
+
server_url: "https://test.identity.dhamma.org"
|
42
|
+
}
|
43
|
+
```
|
44
|
+
|
50
45
|
## Use VIS API
|
51
46
|
|
52
47
|
`Vis::Api` will implement [Oauth2 Client Credentials Flow](https://auth0.com/docs/get-started/authentication-and-authorization-flow/client-credentials-flow) behind the scene
|
@@ -58,7 +53,7 @@ require "vis/api"
|
|
58
53
|
@vis_api.post("api_path", data)
|
59
54
|
```
|
60
55
|
|
61
|
-
Documentation about available api can be found at [https://
|
56
|
+
Documentation about available api can be found at [https://identity.dhamma.org/doc](https://identity.dhamma.org/doc)
|
62
57
|
|
63
58
|
Example
|
64
59
|
|
@@ -13,6 +13,7 @@ module OmniAuth
|
|
13
13
|
option :scope, 'default'
|
14
14
|
|
15
15
|
option :server_url, "https://identity.dhamma.org"
|
16
|
+
option :jwt_shared_secret, nil
|
16
17
|
|
17
18
|
def setup_phase
|
18
19
|
# configure Oauth2 client_options.site from a custom server_url option
|
@@ -42,7 +43,20 @@ module OmniAuth
|
|
42
43
|
end
|
43
44
|
|
44
45
|
def raw_info
|
45
|
-
@raw_info
|
46
|
+
return @raw_info if @raw_info.present?
|
47
|
+
|
48
|
+
@raw_info = if options.jwt_shared_secret.present?
|
49
|
+
# get info from the JWT token, so we save an API call
|
50
|
+
JWT.decode(
|
51
|
+
access_token.token,
|
52
|
+
options.jwt_shared_secret,
|
53
|
+
true,
|
54
|
+
{ algorithm: "hs512" }
|
55
|
+
).first["user"]
|
56
|
+
else
|
57
|
+
# get info from API
|
58
|
+
access_token.get("/api/v1/me.json").parsed
|
59
|
+
end
|
46
60
|
end
|
47
61
|
end
|
48
62
|
end
|
data/lib/vis/api.rb
CHANGED
@@ -1,6 +1,8 @@
|
|
1
1
|
# Vipassna Identity Server Service - for server to server Oauth 2 client_credentials grant flow
|
2
2
|
# gets tokens so we can use the VIS API
|
3
3
|
module Vis
|
4
|
+
class OauthError < StandardError
|
5
|
+
|
4
6
|
class Api
|
5
7
|
def initialize(server_url: "https://identity.dhamma.org", client_id:, client_secret:)
|
6
8
|
@client_id = client_id
|
@@ -24,7 +26,7 @@ module Vis
|
|
24
26
|
private def check_error!(response_code, response_body_hash)
|
25
27
|
return unless response_body_hash["error"].present? || !response_code.in?(["200", "202"]) # 201 ?
|
26
28
|
|
27
|
-
raise
|
29
|
+
raise Vis::OauthError,
|
28
30
|
"#{response_code} Error requesting token from Vipassana Identity Server. "\
|
29
31
|
"#{response_body_hash['error']} #{response_body_hash['error_description']}"
|
30
32
|
end
|
data/omniauth-vis.gemspec
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |gem|
|
4
4
|
gem.name = 'omniauth-vis'
|
5
|
-
gem.version = '0.1.
|
5
|
+
gem.version = '0.1.2'
|
6
6
|
# gem.license = 'MIT'
|
7
7
|
gem.summary = 'Helper to connect to Vipassna Identity Server'
|
8
8
|
gem.description = 'This allows you to connect to Vipassana identity server with your ruby app'
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: omniauth-vis
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dhamma workers
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-
|
11
|
+
date: 2023-10-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: omniauth-oauth2
|