omniauth-auth0 3.0.0 → 3.1.1

Sign up to get free protection for your applications and to get access to all the features.
data/EXAMPLES.md ADDED
@@ -0,0 +1,181 @@
1
+ * [Example of the resulting authentication hash](#example-of-the-resulting-authentication-hash)
2
+ * [Send additional authentication parameters](#send-additional-authentication-parameters)
3
+ * [Query Parameter Options](#query-parameter-options)
4
+ * [Auth0 Organizations](#auth0-organizations)
5
+ - [Logging in with an Organization](#logging-in-with-an-organization)
6
+ - [Validating Organizations when using Organization Login Prompt](#validating-organizations-when-using-organization-login-prompt)
7
+ - [Accepting user invitations](#accepting-user-invitations)
8
+
9
+ ### Example of the resulting authentication hash
10
+
11
+ The Auth0 strategy will provide the standard OmniAuth hash attributes:
12
+
13
+ - `:provider` - the name of the strategy, in this case `auth0`
14
+ - `:uid` - the user identifier
15
+ - `:info` - the result of the call to `/userinfo` using OmniAuth standard attributes
16
+ - `:credentials` - tokens requested and data
17
+ - `:extra` - Additional info obtained from calling `/userinfo` in the `:raw_info` property
18
+
19
+ ```ruby
20
+ {
21
+ :provider => 'auth0',
22
+ :uid => 'auth0|USER_ID',
23
+ :info => {
24
+ :name => 'John Foo',
25
+ :email => 'johnfoo@example.org',
26
+ :nickname => 'john',
27
+ :image => 'https://example.org/john.jpg'
28
+ },
29
+ :credentials => {
30
+ :token => 'ACCESS_TOKEN',
31
+ :expires_at => 1485373937,
32
+ :expires => true,
33
+ :refresh_token => 'REFRESH_TOKEN',
34
+ :id_token => 'JWT_ID_TOKEN',
35
+ :token_type => 'bearer',
36
+ },
37
+ :extra => {
38
+ :raw_info => {
39
+ :email => 'johnfoo@example.org',
40
+ :email_verified => 'true',
41
+ :name => 'John Foo',
42
+ :picture => 'https://example.org/john.jpg',
43
+ :user_id => 'auth0|USER_ID',
44
+ :nickname => 'john',
45
+ :created_at => '2014-07-15T17:19:50.387Z'
46
+ }
47
+ }
48
+ }
49
+ ```
50
+
51
+ ## Send additional authentication parameters
52
+
53
+ To send additional parameters during login, you can specify them when you register the provider:
54
+
55
+ ```ruby
56
+ provider
57
+ :auth0,
58
+ ENV['AUTH0_CLIENT_ID'],
59
+ ENV['AUTH0_CLIENT_SECRET'],
60
+ ENV['AUTH0_DOMAIN'],
61
+ {
62
+ authorize_params: {
63
+ scope: 'openid read:users write:order',
64
+ audience: 'https://mydomain/api',
65
+ max_age: 3600 # time in seconds authentication is valid
66
+ }
67
+ }
68
+ ```
69
+
70
+ This will tell the strategy to send those parameters on every authentication request.
71
+
72
+ ## Query Parameter Options
73
+
74
+ In some scenarios, you may need to pass specific query parameters to `/authorize`. The following parameters are available to enable this:
75
+
76
+ - `connection`
77
+ - `connection_scope`
78
+ - `prompt`
79
+ - `screen_hint` (only relevant to New Universal Login Experience)
80
+ - `organization`
81
+ - `invitation`
82
+ - `ui_locales` (only relevant to New Universal Login Experience)
83
+
84
+ Simply pass these query parameters to your OmniAuth redirect endpoint to enable their behavior.
85
+
86
+ ## Auth0 Organizations
87
+
88
+ [Organizations](https://auth0.com/docs/organizations) is a set of features that provide better support for developers who build and maintain SaaS and Business-to-Business (B2B) applications.
89
+
90
+ Note that Organizations is currently only available to customers on our Enterprise and Startup subscription plans.
91
+
92
+ ### Logging in with an Organization
93
+
94
+ Logging in with an Organization is as easy as passing the parameters to the authorize endpoint. You can do this with
95
+
96
+ ```ruby
97
+ <%=
98
+ button_to 'Login', 'auth/auth0',
99
+ method: :post,
100
+ params: {
101
+ # Found in your Auth0 dashboard, under Organization settings:
102
+ organization: '{AUTH0_ORGANIZATION}'
103
+ }
104
+ %>
105
+ ```
106
+
107
+ Alternatively you can configure the organization when you register the provider:
108
+
109
+ ```ruby
110
+ provider
111
+ :auth0,
112
+ ENV['AUTH0_CLIENT_ID'],
113
+ ENV['AUTH0_CLIENT_SECRET'],
114
+ ENV['AUTH0_DOMAIN']
115
+ {
116
+ authorize_params: {
117
+ scope: 'openid read:users',
118
+ audience: 'https://{AUTH0_DOMAIN}/api',
119
+ organization: '{AUTH0_ORGANIZATION}'
120
+ }
121
+ }
122
+ ```
123
+
124
+ When passing `openid` to the scope and `organization` to the authorize params, you will receive an ID token on callback with the `org_id` claim. This claim is validated for you by the SDK.
125
+
126
+ ### Validating Organizations when using Organization Login Prompt
127
+
128
+ When Organization login prompt is enabled on your application, but you haven't specified an Organization for the application's authorization endpoint, `org_id` or `org_name` claims will be present on the ID and access tokens, and should be validated to ensure that the value received is expected or known.
129
+
130
+ Normally, validating the issuer would be enough to ensure that the token was issued by Auth0, and this check is performed by the SDK. However, in the case of organizations, additional checks should be made so that the organization within an Auth0 tenant is expected.
131
+
132
+ In particular, the `org_id` and `org_name` claims should be checked to ensure it is a value that is already known to the application. This could be validated against a known list of organization IDs, or perhaps checked in conjunction with the current request URL. e.g. the sub-domain may hint at what organization should be used to validate the ID Token. For `org_id`, this should be a **case-sensitive, exact match check**. For `org_name`, this should be a **case-insentive check**.
133
+
134
+ The decision to validate the `org_id` or `org_name` claim is determined by the expected organization ID or name having an `org_` prefix.
135
+
136
+ Here is an example using it in your `callback` method
137
+
138
+ ```ruby
139
+ def callback
140
+ claims = request.env['omniauth.auth']['extra']['raw_info']
141
+
142
+ validate_as_id = expected_org.start_with?('org_')
143
+
144
+ if validate_as_id
145
+ if claims["org_id"] && claims["org_id"] !== expected_org
146
+ redirect_to '/unauthorized', status: 401
147
+ else
148
+ session[:userinfo] = claims
149
+ redirect_to '/dashboard'
150
+ end
151
+ else
152
+ if claims["org_name"] && claims["org_name"].downcase !== expected_org.downcase
153
+ redirect_to '/unauthorized', status: 401
154
+ else
155
+ session[:userinfo] = claims
156
+ redirect_to '/dashboard'
157
+ end
158
+ end
159
+ end
160
+ ```
161
+
162
+ For more information, please read [Work with Tokens and Organizations](https://auth0.com/docs/organizations/using-tokens) on Auth0 Docs.
163
+
164
+ ### Accepting user invitations
165
+
166
+ Auth0 Organizations allow users to be invited using emailed links, which will direct a user back to your application. The URL the user will arrive at is based on your configured `Application Login URI`, which you can change from your Application's settings inside the Auth0 dashboard.
167
+
168
+ When the user arrives at your application using an invite link, you can expect three query parameters to be provided: `invitation`, `organization`, and `organization_name`. These will always be delivered using a GET request.
169
+
170
+ You can then supply those parametrs to a `button_to` or `link_to` helper
171
+
172
+ ```ruby
173
+ <%=
174
+ button_to 'Login', 'auth/auth0',
175
+ method: :post,
176
+ params: {
177
+ organization: '{YOUR_ORGANIZATION_ID}',
178
+ invitation: '{INVITE_CODE}'
179
+ }
180
+ %>
181
+ ```
data/Gemfile CHANGED
@@ -2,25 +2,25 @@ source 'https://rubygems.org'
2
2
 
3
3
  gemspec
4
4
 
5
- gem 'gem-release'
6
- gem 'jwt'
7
- gem 'rake'
5
+ gem 'gem-release', '~> 2'
6
+ gem 'jwt', '~> 2'
7
+ gem 'rake', '~> 13'
8
8
 
9
9
  group :development do
10
- gem 'dotenv'
11
- gem 'pry'
12
- gem 'rubocop', require: false
13
- gem 'shotgun'
14
- gem 'sinatra'
15
- gem 'thin'
10
+ gem 'dotenv', '~> 2'
11
+ gem 'pry', '~> 0'
12
+ gem 'rubocop', '~> 1', require: false
13
+ gem 'shotgun', '~> 0', '>= 0.9.2'
14
+ gem 'sinatra', '~> 3'
15
+ gem 'thin', '~> 1'
16
16
  end
17
17
 
18
18
  group :test do
19
- gem 'guard-rspec', require: false
19
+ gem 'guard-rspec', '~> 4', require: false
20
20
  gem 'listen', '~> 3'
21
- gem 'rack-test'
22
- gem 'rspec', '~> 3.5'
23
- gem 'codecov', require: false
24
- gem 'simplecov'
25
- gem 'webmock'
21
+ gem 'rack-test', '~> 2', '>= 2.0.2'
22
+ gem 'rspec', '~> 3'
23
+ gem 'simplecov-cobertura', '~> 2'
24
+ gem 'webmock', '~> 3'
25
+ gem 'multi_json', '~> 1'
26
26
  end
data/Gemfile.lock ADDED
@@ -0,0 +1,184 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ omniauth-auth0 (3.1.1)
5
+ omniauth (~> 2)
6
+ omniauth-oauth2 (~> 1)
7
+
8
+ GEM
9
+ remote: https://rubygems.org/
10
+ specs:
11
+ addressable (2.8.4)
12
+ public_suffix (>= 2.0.2, < 6.0)
13
+ ast (2.4.2)
14
+ coderay (1.1.3)
15
+ crack (0.4.5)
16
+ rexml
17
+ daemons (1.4.1)
18
+ diff-lcs (1.5.0)
19
+ docile (1.4.0)
20
+ dotenv (2.8.1)
21
+ eventmachine (1.2.7)
22
+ faraday (2.7.10)
23
+ faraday-net_http (>= 2.0, < 3.1)
24
+ ruby2_keywords (>= 0.0.4)
25
+ faraday-net_http (3.0.2)
26
+ ffi (1.15.5)
27
+ formatador (1.1.0)
28
+ gem-release (2.2.2)
29
+ guard (2.18.0)
30
+ formatador (>= 0.2.4)
31
+ listen (>= 2.7, < 4.0)
32
+ lumberjack (>= 1.0.12, < 2.0)
33
+ nenv (~> 0.1)
34
+ notiffany (~> 0.0)
35
+ pry (>= 0.13.0)
36
+ shellany (~> 0.0)
37
+ thor (>= 0.18.1)
38
+ guard-compat (1.2.1)
39
+ guard-rspec (4.7.3)
40
+ guard (~> 2.1)
41
+ guard-compat (~> 1.1)
42
+ rspec (>= 2.99.0, < 4.0)
43
+ hashdiff (1.0.1)
44
+ hashie (5.0.0)
45
+ json (2.6.3)
46
+ jwt (2.7.1)
47
+ language_server-protocol (3.17.0.3)
48
+ listen (3.8.0)
49
+ rb-fsevent (~> 0.10, >= 0.10.3)
50
+ rb-inotify (~> 0.9, >= 0.9.10)
51
+ lumberjack (1.2.8)
52
+ method_source (1.0.0)
53
+ multi_json (1.15.0)
54
+ multi_xml (0.6.0)
55
+ mustermann (3.0.0)
56
+ ruby2_keywords (~> 0.0.1)
57
+ nenv (0.3.0)
58
+ notiffany (0.1.3)
59
+ nenv (~> 0.1)
60
+ shellany (~> 0.0)
61
+ oauth2 (2.0.9)
62
+ faraday (>= 0.17.3, < 3.0)
63
+ jwt (>= 1.0, < 3.0)
64
+ multi_xml (~> 0.5)
65
+ rack (>= 1.2, < 4)
66
+ snaky_hash (~> 2.0)
67
+ version_gem (~> 1.1)
68
+ omniauth (2.1.1)
69
+ hashie (>= 3.4.6)
70
+ rack (>= 2.2.3)
71
+ rack-protection
72
+ omniauth-oauth2 (1.8.0)
73
+ oauth2 (>= 1.4, < 3)
74
+ omniauth (~> 2.0)
75
+ parallel (1.23.0)
76
+ parser (3.2.2.3)
77
+ ast (~> 2.4.1)
78
+ racc
79
+ pry (0.14.2)
80
+ coderay (~> 1.1)
81
+ method_source (~> 1.0)
82
+ public_suffix (5.0.3)
83
+ racc (1.7.1)
84
+ rack (2.2.7)
85
+ rack-protection (3.0.6)
86
+ rack
87
+ rack-test (2.1.0)
88
+ rack (>= 1.3)
89
+ rainbow (3.1.1)
90
+ rake (13.0.6)
91
+ rb-fsevent (0.11.2)
92
+ rb-inotify (0.10.1)
93
+ ffi (~> 1.0)
94
+ regexp_parser (2.8.1)
95
+ rexml (3.2.5)
96
+ rspec (3.12.0)
97
+ rspec-core (~> 3.12.0)
98
+ rspec-expectations (~> 3.12.0)
99
+ rspec-mocks (~> 3.12.0)
100
+ rspec-core (3.12.2)
101
+ rspec-support (~> 3.12.0)
102
+ rspec-expectations (3.12.3)
103
+ diff-lcs (>= 1.2.0, < 2.0)
104
+ rspec-support (~> 3.12.0)
105
+ rspec-mocks (3.12.6)
106
+ diff-lcs (>= 1.2.0, < 2.0)
107
+ rspec-support (~> 3.12.0)
108
+ rspec-support (3.12.1)
109
+ rubocop (1.54.2)
110
+ json (~> 2.3)
111
+ language_server-protocol (>= 3.17.0)
112
+ parallel (~> 1.10)
113
+ parser (>= 3.2.2.3)
114
+ rainbow (>= 2.2.2, < 4.0)
115
+ regexp_parser (>= 1.8, < 3.0)
116
+ rexml (>= 3.2.5, < 4.0)
117
+ rubocop-ast (>= 1.28.0, < 2.0)
118
+ ruby-progressbar (~> 1.7)
119
+ unicode-display_width (>= 2.4.0, < 3.0)
120
+ rubocop-ast (1.29.0)
121
+ parser (>= 3.2.1.0)
122
+ ruby-progressbar (1.13.0)
123
+ ruby2_keywords (0.0.5)
124
+ shellany (0.0.1)
125
+ shotgun (0.9.2)
126
+ rack (>= 1.0)
127
+ simplecov (0.22.0)
128
+ docile (~> 1.1)
129
+ simplecov-html (~> 0.11)
130
+ simplecov_json_formatter (~> 0.1)
131
+ simplecov-cobertura (2.1.0)
132
+ rexml
133
+ simplecov (~> 0.19)
134
+ simplecov-html (0.12.3)
135
+ simplecov_json_formatter (0.1.4)
136
+ sinatra (3.0.6)
137
+ mustermann (~> 3.0)
138
+ rack (~> 2.2, >= 2.2.4)
139
+ rack-protection (= 3.0.6)
140
+ tilt (~> 2.0)
141
+ snaky_hash (2.0.1)
142
+ hashie
143
+ version_gem (~> 1.1, >= 1.1.1)
144
+ thin (1.8.2)
145
+ daemons (~> 1.0, >= 1.0.9)
146
+ eventmachine (~> 1.0, >= 1.0.4)
147
+ rack (>= 1, < 3)
148
+ thor (1.2.2)
149
+ tilt (2.2.0)
150
+ unicode-display_width (2.4.2)
151
+ version_gem (1.1.3)
152
+ webmock (3.18.1)
153
+ addressable (>= 2.8.0)
154
+ crack (>= 0.3.2)
155
+ hashdiff (>= 0.4.0, < 2.0.0)
156
+
157
+ PLATFORMS
158
+ aarch64-linux
159
+ arm64-darwin-21
160
+ x86_64-darwin-22
161
+ x86_64-linux
162
+
163
+ DEPENDENCIES
164
+ bundler
165
+ dotenv (~> 2)
166
+ gem-release (~> 2)
167
+ guard-rspec (~> 4)
168
+ jwt (~> 2)
169
+ listen (~> 3)
170
+ multi_json (~> 1)
171
+ omniauth-auth0!
172
+ pry (~> 0)
173
+ rack-test (~> 2, >= 2.0.2)
174
+ rake (~> 13)
175
+ rspec (~> 3)
176
+ rubocop (~> 1)
177
+ shotgun (~> 0, >= 0.9.2)
178
+ simplecov-cobertura (~> 2)
179
+ sinatra (~> 3)
180
+ thin (~> 1)
181
+ webmock (~> 3)
182
+
183
+ BUNDLED WITH
184
+ 2.3.7