Class: GdsApi::AccountApi
Overview
Adapter for the Account API
Constant Summary collapse
- AUTH_HEADER_NAME =
"GOVUK-Account-Session".freeze
Instance Attribute Summary
Attributes inherited from Base
Instance Method Summary collapse
-
#delete_user_by_subject_identifier(subject_identifier:) ⇒ Object
Delete a users account.
-
#get_attributes(attributes:, govuk_account_session:) ⇒ Hash
Look up the values of a user’s attributes.
-
#get_end_session_url(govuk_account_session: nil) ⇒ Hash
Get an OIDC end-session URL to redirect the user to.
-
#get_sign_in_url(redirect_path: nil, mfa: false) ⇒ Hash
Get an OAuth sign-in URL to redirect the user to.
-
#get_user(govuk_account_session:) ⇒ Hash
Get all the information about a user needed to render the account home page.
-
#match_user_by_email(email:, govuk_account_session: nil) ⇒ Hash
Find a user by email address, returning whether they match the given session (if any).
-
#set_attributes(attributes:, govuk_account_session:) ⇒ Hash
Create or update attributes for a user.
-
#update_user_by_subject_identifier(subject_identifier:, email: nil, email_verified: nil) ⇒ Hash
Update the user record with privileged information from the auth service.
-
#validate_auth_response(code:, state:) ⇒ Hash
Validate an OAuth authentication response.
Methods inherited from Base
#client, #create_client, #get_list, #initialize, #url_for_slug
Constructor Details
This class inherits a constructor from GdsApi::Base
Instance Method Details
#delete_user_by_subject_identifier(subject_identifier:) ⇒ Object
Delete a users account
69 70 71 |
# File 'lib/gds_api/account_api.rb', line 69 def delete_user_by_subject_identifier(subject_identifier:) delete_json("#{endpoint}/api/oidc-users/#{subject_identifier}") end |
#get_attributes(attributes:, govuk_account_session:) ⇒ Hash
Look up the values of a user’s attributes
95 96 97 98 |
# File 'lib/gds_api/account_api.rb', line 95 def get_attributes(attributes:, govuk_account_session:) querystring = nested_query_string({ attributes: }.compact) get_json("#{endpoint}/api/attributes?#{querystring}", auth_headers(govuk_account_session)) end |
#get_end_session_url(govuk_account_session: nil) ⇒ Hash
Get an OIDC end-session URL to redirect the user to
42 43 44 |
# File 'lib/gds_api/account_api.rb', line 42 def get_end_session_url(govuk_account_session: nil) get_json("#{endpoint}/api/oauth2/end-session", auth_headers(govuk_account_session)) end |
#get_sign_in_url(redirect_path: nil, mfa: false) ⇒ Hash
Get an OAuth sign-in URL to redirect the user to
17 18 19 20 21 22 23 24 25 |
# File 'lib/gds_api/account_api.rb', line 17 def get_sign_in_url(redirect_path: nil, mfa: false) querystring = nested_query_string( { redirect_path:, mfa:, }.compact, ) get_json("#{endpoint}/api/oauth2/sign-in?#{querystring}") end |
#get_user(govuk_account_session:) ⇒ Hash
Get all the information about a user needed to render the account home page
51 52 53 |
# File 'lib/gds_api/account_api.rb', line 51 def get_user(govuk_account_session:) get_json("#{endpoint}/api/user", auth_headers(govuk_account_session)) end |
#match_user_by_email(email:, govuk_account_session: nil) ⇒ Hash
Find a user by email address, returning whether they match the given session (if any)
61 62 63 64 |
# File 'lib/gds_api/account_api.rb', line 61 def match_user_by_email(email:, govuk_account_session: nil) querystring = nested_query_string({ email: }) get_json("#{endpoint}/api/user/match-by-email?#{querystring}", auth_headers(govuk_account_session)) end |
#set_attributes(attributes:, govuk_account_session:) ⇒ Hash
Create or update attributes for a user
106 107 108 |
# File 'lib/gds_api/account_api.rb', line 106 def set_attributes(attributes:, govuk_account_session:) patch_json("#{endpoint}/api/attributes", { attributes: }, auth_headers(govuk_account_session)) end |
#update_user_by_subject_identifier(subject_identifier:, email: nil, email_verified: nil) ⇒ Hash
Update the user record with privileged information from the auth service. Only the auth service will call this.
80 81 82 83 84 85 86 87 |
# File 'lib/gds_api/account_api.rb', line 80 def update_user_by_subject_identifier(subject_identifier:, email: nil, email_verified: nil) params = { email:, email_verified:, }.compact patch_json("#{endpoint}/api/oidc-users/#{subject_identifier}", params) end |
#validate_auth_response(code:, state:) ⇒ Hash
Validate an OAuth authentication response
33 34 35 |
# File 'lib/gds_api/account_api.rb', line 33 def validate_auth_response(code:, state:) post_json("#{endpoint}/api/oauth2/callback", code:, state:) end |