|
3 | 3 | # This file is auto-generated by oagen. Do not edit. |
4 | 4 |
|
5 | 5 | require "json" |
| 6 | +require "uri" |
6 | 7 |
|
7 | 8 | module WorkOS |
8 | 9 | class UserManagement |
@@ -515,6 +516,70 @@ def authenticate_with_radar_sms_challenge( |
515 | 516 | WorkOS::AuthenticateResponse.new(response.body) |
516 | 517 | end |
517 | 518 |
|
| 519 | + # Get an authorization URL |
| 520 | + # Builds the URL client-side; no HTTP request is made. |
| 521 | + # @param code_challenge_method [String, nil] The only valid PKCE code challenge method is `"S256"`. Required when specifying a `code_challenge`. |
| 522 | + # @param code_challenge [String, nil] Code challenge derived from the code verifier used for the PKCE flow. |
| 523 | + # @param domain_hint [String, nil] A domain hint for SSO connection lookup. |
| 524 | + # @param connection_id [String, nil] The ID of an SSO connection to use for authentication. |
| 525 | + # @param provider_query_params [Hash{String => String}, nil] Key/value pairs of query parameters to pass to the OAuth provider. |
| 526 | + # @param provider_scopes [Array<String>, nil] Additional OAuth scopes to request from the identity provider. |
| 527 | + # @param invitation_token [String, nil] A token representing a user invitation to redeem during authentication. |
| 528 | + # @param max_age [Integer, nil] Maximum allowable elapsed time, in seconds, since the user last actively authenticated. If the last authentication is older than this value, the user is prompted to re-authenticate; a value of `0` forces re-authentication. Only supported when the provider is `authkit`. |
| 529 | + # @param screen_hint [WorkOS::Types::UserManagementAuthenticationScreenHint, nil] Used to specify which screen to display when the provider is `authkit`. |
| 530 | + # @param login_hint [String, nil] A hint to the authorization server about the login identifier the user might use. |
| 531 | + # @param provider [WorkOS::Types::UserManagementAuthenticationProvider, nil] The OAuth provider to authenticate with (e.g., GoogleOAuth, MicrosoftOAuth, GitHubOAuth). |
| 532 | + # @param prompt [String, nil] Controls the authentication flow behavior for the user. |
| 533 | + # @param state [String, nil] An opaque value used to maintain state between the request and the callback. |
| 534 | + # @param organization_id [String, nil] The ID of the organization to authenticate the user against. |
| 535 | + # @param redirect_uri [String] The callback URI where the authorization code will be sent after authentication. |
| 536 | + # @param client_id [String, nil] The unique identifier of the WorkOS environment client. Defaults to the client's configured client_id. |
| 537 | + # @return [String] |
| 538 | + def get_authorization_url( |
| 539 | + redirect_uri:, |
| 540 | + code_challenge_method: nil, |
| 541 | + code_challenge: nil, |
| 542 | + domain_hint: nil, |
| 543 | + connection_id: nil, |
| 544 | + provider_query_params: nil, |
| 545 | + provider_scopes: nil, |
| 546 | + invitation_token: nil, |
| 547 | + max_age: nil, |
| 548 | + screen_hint: nil, |
| 549 | + login_hint: nil, |
| 550 | + provider: nil, |
| 551 | + prompt: nil, |
| 552 | + state: nil, |
| 553 | + organization_id: nil, |
| 554 | + client_id: nil |
| 555 | + ) |
| 556 | + params = { |
| 557 | + "code_challenge_method" => code_challenge_method, |
| 558 | + "code_challenge" => code_challenge, |
| 559 | + "domain_hint" => domain_hint, |
| 560 | + "connection_id" => connection_id, |
| 561 | + "provider_query_params" => provider_query_params, |
| 562 | + "provider_scopes" => provider_scopes, |
| 563 | + "invitation_token" => invitation_token, |
| 564 | + "max_age" => max_age, |
| 565 | + "screen_hint" => screen_hint, |
| 566 | + "login_hint" => login_hint, |
| 567 | + "provider" => provider, |
| 568 | + "prompt" => prompt, |
| 569 | + "state" => state, |
| 570 | + "organization_id" => organization_id, |
| 571 | + "redirect_uri" => redirect_uri, |
| 572 | + "client_id" => client_id |
| 573 | + }.compact |
| 574 | + params["provider_query_params"] = JSON.generate(provider_query_params) unless provider_query_params.nil? |
| 575 | + params["provider_scopes"] = provider_scopes.join(",") unless provider_scopes.nil? |
| 576 | + params["response_type"] = "code" |
| 577 | + params["client_id"] = @client.client_id if !params.key?("client_id") && !@client.client_id.nil? |
| 578 | + uri = URI.join(@client.base_url, "/user_management/authorize") |
| 579 | + uri.query = URI.encode_www_form(params) unless params.empty? |
| 580 | + uri.to_s |
| 581 | + end |
| 582 | + |
518 | 583 | # Get device authorization URL |
519 | 584 | # @param client_id [String] The WorkOS client ID for your application. |
520 | 585 | # @param request_options [Hash] (see WorkOS::Types::RequestOptions) |
@@ -592,6 +657,24 @@ def get_radar_challenge( |
592 | 657 | result |
593 | 658 | end |
594 | 659 |
|
| 660 | + # Logout |
| 661 | + # Builds the URL client-side; no HTTP request is made. |
| 662 | + # @param session_id [String] The ID of the session. This can be extracted from the `sid` claim of the access token. |
| 663 | + # @param return_to [String, nil] The URL to redirect the user to after logout. |
| 664 | + # @return [String] |
| 665 | + def get_logout_url( |
| 666 | + session_id:, |
| 667 | + return_to: nil |
| 668 | + ) |
| 669 | + params = { |
| 670 | + "session_id" => session_id, |
| 671 | + "return_to" => return_to |
| 672 | + }.compact |
| 673 | + uri = URI.join(@client.base_url, "/user_management/sessions/logout") |
| 674 | + uri.query = URI.encode_www_form(params) unless params.empty? |
| 675 | + uri.to_s |
| 676 | + end |
| 677 | + |
595 | 678 | # Revoke Session |
596 | 679 | # @param session_id [String] The ID of the session to revoke. This can be extracted from the `sid` claim of the access token. |
597 | 680 | # @param request_options [Hash] (see WorkOS::Types::RequestOptions) |
@@ -1690,32 +1773,10 @@ def get_jwks_url(client_id: nil) |
1690 | 1773 | URI.join(base, "/sso/jwks/#{WorkOS::Util.encode_path(cid)}").to_s |
1691 | 1774 | end |
1692 | 1775 |
|
1693 | | - # H09 — Build an AuthKit authorization URL (client-side, no HTTP call). |
1694 | | - # Overrides the generated get_authorization_url which hits the API. |
1695 | | - def get_authorization_url(redirect_uri:, client_id: nil, provider: nil, connection_id: nil, |
1696 | | - organization_id: nil, domain_hint: nil, login_hint: nil, |
1697 | | - state: nil, screen_hint: nil, code_challenge: nil, |
1698 | | - code_challenge_method: nil, prompt: nil, **) |
1699 | | - cid = client_id || @client.client_id |
1700 | | - raise ArgumentError, "client_id is required (set on Client or pass explicitly)" if cid.nil? || cid.empty? |
1701 | | - raise ArgumentError, "provider, connection_id, or organization_id required" if provider.nil? && connection_id.nil? && organization_id.nil? |
1702 | | - params = { |
1703 | | - "client_id" => cid, |
1704 | | - "redirect_uri" => redirect_uri, |
1705 | | - "response_type" => "code", |
1706 | | - "provider" => provider, |
1707 | | - "connection_id" => connection_id, |
1708 | | - "organization_id" => organization_id, |
1709 | | - "domain_hint" => domain_hint, |
1710 | | - "login_hint" => login_hint, |
1711 | | - "state" => state, |
1712 | | - "screen_hint" => screen_hint, |
1713 | | - "code_challenge" => code_challenge, |
1714 | | - "code_challenge_method" => code_challenge_method, |
1715 | | - "prompt" => prompt |
1716 | | - }.compact |
1717 | | - build_url("/user_management/authorize", params) |
1718 | | - end |
| 1776 | + # H09 (authkit_authorization_url) is provided by the generated |
| 1777 | + # `get_authorization_url` url-builder method, which accepts an optional |
| 1778 | + # per-call `client_id` override falling back to the client's configured |
| 1779 | + # value; no hand-maintained override is needed here. |
1719 | 1780 |
|
1720 | 1781 | # H10 — AuthKit authorization URL with auto-generated PKCE + state. |
1721 | 1782 | # Returns [url, code_verifier, state]. |
@@ -1773,24 +1834,9 @@ def authorize_device(client_id: nil, request_options: {}) |
1773 | 1834 | # `authenticate_with_device_code` method (wraps /user_management/authenticate); |
1774 | 1835 | # no hand-maintained override is needed here. |
1775 | 1836 |
|
1776 | | - # Build the AuthKit logout redirect URL (client-side, no HTTP call). |
1777 | | - # @param session_id [String] The session ID (from the `sid` claim of the access token). |
1778 | | - # @param return_to [String, nil] URL to redirect the user to after session revocation. |
1779 | | - # @return [String] |
1780 | | - def get_logout_url(session_id:, return_to: nil) |
1781 | | - params = {"session_id" => session_id} |
1782 | | - params["return_to"] = return_to if return_to |
1783 | | - build_url("/user_management/sessions/logout", params) |
1784 | | - end |
1785 | | - |
1786 | | - private |
1787 | | - |
1788 | | - def build_url(path, params) |
1789 | | - base = @client.base_url |
1790 | | - uri = URI.join(base, path) |
1791 | | - uri.query = URI.encode_www_form(params) |
1792 | | - uri.to_s |
1793 | | - end |
| 1837 | + # The AuthKit logout redirect URL is provided by the generated |
| 1838 | + # `get_logout_url` url-builder method; no hand-maintained override is |
| 1839 | + # needed here. |
1794 | 1840 | # @oagen-ignore-end |
1795 | 1841 | end |
1796 | 1842 | end |
0 commit comments