gds-api-adapters 72.1.0 → 75.0.0

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: 51407d1cee42f0e1fbdf73f71f91f8e2b179adb56b81a9737ce26e334084644a
4
- data.tar.gz: e8d397558f602abf5989795c92a2ec62880f0919d72897fde2e8e0ce83af2cdc
3
+ metadata.gz: 836544dd1d7130e6ba4f035b660be34e3b108b8ed16f93882cbeb3ee48ea2e6c
4
+ data.tar.gz: 6052c7b0b52ad0bf354b8b97e42fc7e90c98a1ceed2253a8fc501cd4e10b0a6e
5
5
  SHA512:
6
- metadata.gz: 64ea0ab0af3fd9e4f4fe99a8bd8eab5179dc8216a2c45f4e76691150eaf8421d89ba197f923e56246ed5ed1292c49c5697e0c6c56043702e0a0cf1defd0fa402
7
- data.tar.gz: 5a04715d1b8711171adb7d34cafc0f5f4ac499cf5157563c9f39c4fe949fef397ddbc1eab7a40eb9e5f355154cec76ff5b892d7f238515747390a3cb8ec82b3f
6
+ metadata.gz: 220248bfb16db073e03b98e675278f9776eaa5965010ae737a829a352eb0baf9be23630d3eeec10288397341f6ded0bd4da53a94c70fcf53a09843d64c1bee83
7
+ data.tar.gz: f0be992cf2e9324bcefafcbf167f5959d6e993ba9e8530d109785c3868e0961d77b16dd57ec48ac3176688d0dde5c608b7b82d75a8b53626d0ee942ff27294ba
@@ -11,14 +11,14 @@ class GdsApi::AccountApi < GdsApi::Base
11
11
  # Get an OAuth sign-in URL to redirect the user to
12
12
  #
13
13
  # @param [String, nil] redirect_path path on GOV.UK to send the user to after authentication
14
- # @param [String, nil] level_of_authentication either "level1" (require MFA) or "level0" (do not require MFA)
14
+ # @param [Boolean, nil] mfa whether to authenticate the user with MFA or not
15
15
  #
16
16
  # @return [Hash] An authentication URL and the OAuth state parameter (for CSRF protection)
17
- def get_sign_in_url(redirect_path: nil, level_of_authentication: nil)
17
+ def get_sign_in_url(redirect_path: nil, mfa: false)
18
18
  querystring = nested_query_string(
19
19
  {
20
20
  redirect_path: redirect_path,
21
- level_of_authentication: level_of_authentication,
21
+ mfa: mfa,
22
22
  }.compact,
23
23
  )
24
24
  get_json("#{endpoint}/api/oauth2/sign-in?#{querystring}")
@@ -34,6 +34,15 @@ class GdsApi::AccountApi < GdsApi::Base
34
34
  post_json("#{endpoint}/api/oauth2/callback", code: code, state: state)
35
35
  end
36
36
 
37
+ # Get an OIDC end-session URL to redirect the user to
38
+ #
39
+ # @param [String, nil] govuk_account_session Value of the session header
40
+ #
41
+ # @return [Hash] An end-session URL
42
+ def get_end_session_url(govuk_account_session: nil)
43
+ get_json("#{endpoint}/api/oauth2/end-session", auth_headers(govuk_account_session))
44
+ end
45
+
37
46
  # Get all the information about a user needed to render the account home page
38
47
  #
39
48
  # @param [String] govuk_account_session Value of the session header
@@ -89,17 +98,6 @@ class GdsApi::AccountApi < GdsApi::Base
89
98
  patch_json("#{endpoint}/api/attributes", { attributes: attributes }, auth_headers(govuk_account_session))
90
99
  end
91
100
 
92
- # Look up the names of a user's attributes
93
- #
94
- # @param [String] attributes Names of the attributes to check
95
- # @param [String] govuk_account_session Value of the session header
96
- #
97
- # @return [Hash] The attribute names (if present), and a new session header
98
- def get_attributes_names(attributes:, govuk_account_session:)
99
- querystring = nested_query_string({ attributes: attributes }.compact)
100
- get_json("#{endpoint}/api/attributes/names?#{querystring}", auth_headers(govuk_account_session))
101
- end
102
-
103
101
  # Get the details of an account-linked email subscription.
104
102
  #
105
103
  # @param [String] name Name of the subscription
@@ -129,46 +127,6 @@ class GdsApi::AccountApi < GdsApi::Base
129
127
  delete_json("#{endpoint}/api/email-subscriptions/#{CGI.escape(name)}", {}, auth_headers(govuk_account_session))
130
128
  end
131
129
 
132
- # Look up all pages saved by a user in their Account
133
- #
134
- # @param [String] govuk_account_session Value of the session header
135
- #
136
- # @return [Hash] containing :saved_pages, an array of single saved page hashes
137
- def get_saved_pages(govuk_account_session:)
138
- get_json("#{endpoint}/api/saved-pages", auth_headers(govuk_account_session))
139
- end
140
-
141
- # Return a single page by unique URL
142
- #
143
- # @param [String] the path of a page to check
144
- # @param [String] govuk_account_session Value of the session header
145
- #
146
- # @return [Hash] containing :saved_page, a hash of a single saved page value
147
- def get_saved_page(page_path:, govuk_account_session:)
148
- get_json("#{endpoint}/api/saved-pages/#{CGI.escape(page_path)}", auth_headers(govuk_account_session))
149
- end
150
-
151
- # Upsert a single saved page entry in a users account
152
- #
153
- # @param [String] the path of a page to check
154
- # @param [String] govuk_account_session Value of the session header
155
- #
156
- # @return [Hash] A single saved page value (if sucessful)
157
- def save_page(page_path:, govuk_account_session:)
158
- put_json("#{endpoint}/api/saved-pages/#{CGI.escape(page_path)}", {}, auth_headers(govuk_account_session))
159
- end
160
-
161
- # Delete a single saved page entry from a users account
162
- #
163
- # @param [String] the path of a page to check
164
- # @param [String] govuk_account_session Value of the session header
165
- #
166
- # @return [GdsApi::Response] A status code of 204 indicates the saved page has been successfully deleted.
167
- # A status code of 404 indicates there is no saved page with this path.
168
- def delete_saved_page(page_path:, govuk_account_session:)
169
- delete_json("#{endpoint}/api/saved-pages/#{CGI.escape(page_path)}", {}, auth_headers(govuk_account_session))
170
- end
171
-
172
130
  private
173
131
 
174
132
  def nested_query_string(params)
@@ -19,8 +19,8 @@ module GdsApi
19
19
  #########################
20
20
  # GET /api/oauth2/sign-in
21
21
  #########################
22
- def stub_account_api_get_sign_in_url(redirect_path: nil, level_of_authentication: nil, auth_uri: "http://auth/provider", state: "state")
23
- querystring = Rack::Utils.build_nested_query({ redirect_path: redirect_path, level_of_authentication: level_of_authentication }.compact)
22
+ def stub_account_api_get_sign_in_url(redirect_path: nil, mfa: false, auth_uri: "http://auth/provider", state: "state")
23
+ querystring = Rack::Utils.build_nested_query({ redirect_path: redirect_path, mfa: mfa }.compact)
24
24
  stub_request(:get, "#{ACCOUNT_API_ENDPOINT}/api/oauth2/sign-in?#{querystring}")
25
25
  .to_return(
26
26
  status: 200,
@@ -46,16 +46,36 @@ module GdsApi
46
46
  .to_return(status: 401)
47
47
  end
48
48
 
49
+ #############################
50
+ # GET /api/oauth2/end-session
51
+ #############################
52
+ def stub_account_api_get_end_session_url(govuk_account_session: nil, end_session_uri: "http://auth/provider")
53
+ if govuk_account_session
54
+ stub_request(:get, "#{ACCOUNT_API_ENDPOINT}/api/oauth2/end-session")
55
+ .with(headers: { GdsApi::AccountApi::AUTH_HEADER_NAME => govuk_account_session })
56
+ .to_return(
57
+ status: 200,
58
+ body: { end_session_uri: end_session_uri }.to_json,
59
+ )
60
+ else
61
+ stub_request(:get, "#{ACCOUNT_API_ENDPOINT}/api/oauth2/end-session")
62
+ .to_return(
63
+ status: 200,
64
+ body: { end_session_uri: end_session_uri }.to_json,
65
+ )
66
+ end
67
+ end
68
+
49
69
  ###############
50
70
  # GET /api/user
51
71
  ###############
52
- def stub_account_api_user_info(id: "user-id", level_of_authentication: "level0", email: "email@example.com", email_verified: true, has_unconfirmed_email: false, services: {}, **options)
72
+ def stub_account_api_user_info(id: "user-id", mfa: false, email: "email@example.com", email_verified: true, has_unconfirmed_email: false, services: {}, **options)
53
73
  stub_account_api_request(
54
74
  :get,
55
75
  "/api/user",
56
76
  response_body: {
57
77
  id: id,
58
- level_of_authentication: level_of_authentication,
78
+ mfa: mfa,
59
79
  email: email,
60
80
  email_verified: email_verified,
61
81
  has_unconfirmed_email: has_unconfirmed_email,
@@ -236,13 +256,12 @@ module GdsApi
236
256
  )
237
257
  end
238
258
 
239
- def stub_account_api_forbidden_has_attributes(attributes: [], needed_level_of_authentication: "level1", **options)
259
+ def stub_account_api_forbidden_has_attributes(attributes: [], **options)
240
260
  querystring = Rack::Utils.build_nested_query({ attributes: attributes }.compact)
241
261
  stub_account_api_request(
242
262
  :get,
243
263
  "/api/attributes?#{querystring}",
244
264
  response_status: 403,
245
- response_body: { needed_level_of_authentication: needed_level_of_authentication },
246
265
  **options,
247
266
  )
248
267
  end
@@ -269,184 +288,12 @@ module GdsApi
269
288
  )
270
289
  end
271
290
 
272
- def stub_account_api_forbidden_set_attributes(attributes: nil, needed_level_of_authentication: "level1", **options)
291
+ def stub_account_api_forbidden_set_attributes(attributes: nil, **options)
273
292
  stub_account_api_request(
274
293
  :patch,
275
294
  "/api/attributes",
276
295
  with: { body: hash_including({ attributes: attributes }.compact) },
277
296
  response_status: 403,
278
- response_body: { needed_level_of_authentication: needed_level_of_authentication },
279
- **options,
280
- )
281
- end
282
-
283
- ###########################
284
- # GET /api/attributes/names
285
- ###########################
286
- def stub_account_api_get_attributes_names(attributes: [], **options)
287
- querystring = Rack::Utils.build_nested_query({ attributes: attributes }.compact)
288
- stub_account_api_request(
289
- :get,
290
- "/api/attributes/names?#{querystring}",
291
- response_body: { values: attributes },
292
- **options,
293
- )
294
- end
295
-
296
- def stub_account_api_unauthorized_get_attributes_names(attributes: [], **options)
297
- querystring = Rack::Utils.build_nested_query({ attributes: attributes }.compact)
298
- stub_account_api_request(
299
- :get,
300
- "/api/attributes/names?#{querystring}",
301
- response_status: 401,
302
- **options,
303
- )
304
- end
305
-
306
- def stub_account_api_forbidden_get_attributes_names(attributes: [], needed_level_of_authentication: "level1", **options)
307
- querystring = Rack::Utils.build_nested_query({ attributes: attributes }.compact)
308
- stub_account_api_request(
309
- :get,
310
- "/api/attributes/names?#{querystring}",
311
- response_status: 403,
312
- response_body: { needed_level_of_authentication: needed_level_of_authentication },
313
- **options,
314
- )
315
- end
316
-
317
- ######################
318
- # GET /api/saved-pages
319
- ######################
320
- def stub_account_api_returning_saved_pages(saved_pages: [], **options)
321
- stub_account_api_request(
322
- :get,
323
- "/api/saved-pages",
324
- response_body: { saved_pages: saved_pages },
325
- **options,
326
- )
327
- end
328
-
329
- def stub_account_api_unauthorized_get_saved_pages(**options)
330
- stub_account_api_request(
331
- :get,
332
- "/api/saved-pages",
333
- response_status: 401,
334
- **options,
335
- )
336
- end
337
-
338
- #################################
339
- # GET /api/saved_pages/:page_path
340
- #################################
341
- def stub_account_api_get_saved_page(page_path:, content_id: "46163ed2-1777-4ee6-bdd4-6a2007e49d8f", title: "Ministry of Magic", **options)
342
- stub_account_api_request(
343
- :get,
344
- "/api/saved-pages/#{CGI.escape(page_path)}",
345
- response_body: {
346
- saved_page: {
347
- page_path: page_path,
348
- content_id: content_id,
349
- title: title,
350
- },
351
- },
352
- **options,
353
- )
354
- end
355
-
356
- def stub_account_api_does_not_have_saved_page(page_path:, **options)
357
- stub_account_api_request(
358
- :get,
359
- "/api/saved-pages/#{CGI.escape(page_path)}",
360
- response_status: 404,
361
- **options,
362
- )
363
- end
364
-
365
- def stub_account_api_unauthorized_get_saved_page(page_path:, **options)
366
- stub_account_api_request(
367
- :get,
368
- "/api/saved-pages/#{CGI.escape(page_path)}",
369
- response_status: 401,
370
- **options,
371
- )
372
- end
373
-
374
- #################################
375
- # PUT /api/saved-pages/:page_path
376
- #################################
377
- def stub_account_api_save_page(page_path:, content_id: "c840bfa2-011a-42cc-ac7a-a6da990aff0b", title: "Ministry of Magic", **options)
378
- stub_account_api_request(
379
- :put,
380
- "/api/saved-pages/#{CGI.escape(page_path)}",
381
- response_body: {
382
- saved_page: {
383
- page_path: page_path,
384
- content_id: content_id,
385
- title: title,
386
- },
387
- },
388
- **options,
389
- )
390
- end
391
-
392
- def stub_account_api_save_page_already_exists(page_path:, **options)
393
- stub_account_api_save_page(page_path: page_path, **options)
394
- end
395
-
396
- def stub_account_api_save_page_cannot_save_page(page_path:, **options)
397
- stub_account_api_request(
398
- :put,
399
- "/api/saved-pages/#{CGI.escape(page_path)}",
400
- response_status: 422,
401
- response_body: cannot_save_page_problem_detail({ page_path: page_path }),
402
- **options,
403
- )
404
- end
405
-
406
- def stub_account_api_unauthorized_save_page(page_path:, **options)
407
- stub_account_api_request(
408
- :put,
409
- "/api/saved-pages/#{CGI.escape(page_path)}",
410
- response_status: 401,
411
- **options,
412
- )
413
- end
414
-
415
- def cannot_save_page_problem_detail(option = {})
416
- {
417
- title: "Cannot save page",
418
- detail: "Cannot save page with path #{option['page_path']}, check it is not blank, and is a well formatted url path.",
419
- type: "https://github.com/alphagov/account-api/blob/main/docs/api.md#cannot-save-page",
420
- **option,
421
- }
422
- end
423
-
424
- ####################################
425
- # DELETE /api/saved-pages/:page_path
426
- ####################################
427
- def stub_account_api_delete_saved_page(page_path:, **options)
428
- stub_account_api_request(
429
- :delete,
430
- "/api/saved-pages/#{CGI.escape(page_path)}",
431
- response_status: 204,
432
- **options,
433
- )
434
- end
435
-
436
- def stub_account_api_delete_saved_page_does_not_exist(page_path:, **options)
437
- stub_account_api_request(
438
- :delete,
439
- "/api/saved-pages/#{CGI.escape(page_path)}",
440
- response_status: 404,
441
- **options,
442
- )
443
- end
444
-
445
- def stub_account_api_unauthorized_delete_saved_page(page_path:, **options)
446
- stub_account_api_request(
447
- :delete,
448
- "/api/saved-pages/#{CGI.escape(page_path)}",
449
- response_status: 401,
450
297
  **options,
451
298
  )
452
299
  end
@@ -1,3 +1,3 @@
1
1
  module GdsApi
2
- VERSION = "72.1.0".freeze
2
+ VERSION = "75.0.0".freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gds-api-adapters
3
3
  version: !ruby/object:Gem::Version
4
- version: 72.1.0
4
+ version: 75.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - GOV.UK Dev
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-07-27 00:00:00.000000000 Z
11
+ date: 2021-09-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: addressable