omniauth-vis 0.0.9 → 0.1.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b14af6f1e3470751c7d59576d8f4e36955bbac66993a428c4ad25cc7c0c55c93
4
- data.tar.gz: 238c6eb40d541a52ed53c28dec01cffce45f3a96ed145b14cb44d34c943e71aa
3
+ metadata.gz: d8b432afa787a07d440f818da3dd85c4f41fd2e88120d753008412ab604c4a7d
4
+ data.tar.gz: caedc53baba391f1ea8d753b7645344648c9959b11b0fcafeef0073a9597ee74
5
5
  SHA512:
6
- metadata.gz: '01120799fc73d04e6efec71f0110728862a4375d46d29a99946420337e8982f5165b95ab443a69ba5fbf3ad0901303afc5d26e2624d38e508afdb4108e77d4a2'
7
- data.tar.gz: c07bbb587a80adf75747e9f526b1366c470a060365dd995590742b5955b7cf88fd9a02f0988c79f83f854f2f40dd8d5cdcf449377d24ffd6de7e1d8a41f5bf75
6
+ metadata.gz: 3bfc2458abb1627789dd5bfc839b1880a5ba2baeae6b86a9aa5f70f87aea8836e434a1a207fd15840ad6353890f82ac47ce3cf21303b3f6f15d76f241885a6b2
7
+ data.tar.gz: e0de88030cf8d44c98413f2b180890e4f38d1b4d3056dd8b209ec924c6c67194c91eda14cd75774e0fd8b419a6adf7e8477d37f7dadebf9ea9bf836f9ac2a10d
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://test.identity.dhamma.org/doc](https://test.identity.dhamma.org/doc)
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
 
@@ -8,18 +8,19 @@ module OmniAuth
8
8
  option :name, :vis
9
9
 
10
10
  option :client_options,
11
- site: Rails.application.config.vis['server_url'],
12
11
  authorize_path: '/oauth/authorize'
13
12
 
14
13
  option :scope, 'default'
15
14
 
16
- def on_path?(path)
17
- current_path.squeeze('/').casecmp(path.squeeze('/')).zero?
18
- end
15
+ option :server_url, "https://identity.dhamma.org"
16
+ option :jwt_shared_secret, nil
19
17
 
20
18
  def setup_phase
19
+ # configure Oauth2 client_options.site from a custom server_url option
20
+ options.client_options.site = options.server_url
21
+
21
22
  # Authorize all params to be passed to VIS
22
- request.env['omniauth.strategy'].options[:authorize_params] = request.params.to_h
23
+ options.authorize_params = request.params.to_h
23
24
  end
24
25
 
25
26
  uid do
@@ -30,6 +31,11 @@ module OmniAuth
30
31
  raw_info
31
32
  end
32
33
 
34
+ # Fix strange bugs with urls containing double / like dhamma.org//oauth/callback
35
+ def on_path?(path)
36
+ current_path.squeeze('/').casecmp(path.squeeze('/')).zero?
37
+ end
38
+
33
39
  # to fix always getting invalid_grant error
34
40
  # see https://github.com/omniauth/omniauth-oauth2/issues/81#issuecomment-231442739
35
41
  def callback_url
@@ -37,7 +43,20 @@ module OmniAuth
37
43
  end
38
44
 
39
45
  def raw_info
40
- @raw_info ||= access_token.get('/api/v1/me.json').parsed
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
41
60
  end
42
61
  end
43
62
  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.0.9'
5
+ gem.version = '0.1.1'
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.0.9
4
+ version: 0.1.1
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-07-06 00:00:00.000000000 Z
11
+ date: 2023-09-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: omniauth-oauth2