stytch 5.0.2 → 6.0.0

Sign up to get free protection for your applications and to get access to all the features.
data/lib/stytch/oauth.rb CHANGED
@@ -1,54 +1,161 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ # !!!
4
+ # WARNING: This file is autogenerated
5
+ # Only modify code within MANUAL() sections
6
+ # or your changes may be overwritten later!
7
+ # !!!
8
+
3
9
  require_relative 'request_helper'
4
10
 
5
11
  module Stytch
6
12
  class OAuth
7
13
  include Stytch::RequestHelper
8
14
 
9
- PATH = '/v1/oauth'
10
-
11
15
  def initialize(connection)
12
16
  @connection = connection
13
17
  end
14
18
 
15
- def authenticate(
16
- token:,
19
+ # Generate an OAuth Attach Token to pre-associate an OAuth flow with an existing Stytch User. Pass the returned `oauth_attach_token` to the same provider's OAuth Start endpoint to treat this OAuth flow as a login for that user instead of a signup for a new user.
20
+ #
21
+ # Exactly one of `user_id`, `session_token`, or `session_jwt` must be provided to identify the target Stytch User.
22
+ #
23
+ # This is an optional step in the OAuth flow. Stytch can often determine whether to create a new user or log in an existing one based on verified identity provider information. This endpoint is useful for cases where we can't, such as missing or unverified provider information.
24
+ #
25
+ # == Parameters:
26
+ # provider::
27
+ # The OAuth provider's name.
28
+ # The type of this field is +String+.
29
+ # user_id::
30
+ # The unique ID of a specific User.
31
+ # The type of this field is nilable +String+.
32
+ # session_token::
33
+ # The `session_token` associated with a User's existing Session.
34
+ # The type of this field is nilable +String+.
35
+ # session_jwt::
36
+ # The `session_jwt` associated with a User's existing Session.
37
+ # The type of this field is nilable +String+.
38
+ #
39
+ # == Returns:
40
+ # An object with the following fields:
41
+ # request_id::
42
+ # Globally unique UUID that is returned with every API call. This value is important to log for debugging purposes; we may ask for this value to help identify a specific API call when helping you debug an issue.
43
+ # The type of this field is +String+.
44
+ # oauth_attach_token::
45
+ # A single-use token for connecting the Stytch User selection from an OAuth Attach request to the corresponding OAuth Start request.
46
+ # The type of this field is +String+.
47
+ # status_code::
48
+ # The HTTP status code of the response. Stytch follows standard HTTP response status code patterns, e.g. 2XX values equate to success, 3XX values are redirects, 4XX are client errors, and 5XX are server errors.
49
+ # The type of this field is +Integer+.
50
+ def attach(
51
+ provider:,
52
+ user_id: nil,
17
53
  session_token: nil,
18
- session_jwt: nil,
19
- session_duration_minutes: nil,
20
- session_custom_claims: nil,
21
- code_verifier: nil
54
+ session_jwt: nil
22
55
  )
23
56
  request = {
24
- token: token
57
+ provider: provider
25
58
  }
59
+ request[:user_id] = user_id unless user_id.nil?
26
60
  request[:session_token] = session_token unless session_token.nil?
27
61
  request[:session_jwt] = session_jwt unless session_jwt.nil?
28
- request[:session_duration_minutes] = session_duration_minutes unless session_duration_minutes.nil?
29
- request[:session_custom_claims] = session_custom_claims unless session_custom_claims.nil?
30
- request[:code_verifier] = code_verifier unless code_verifier.nil?
31
62
 
32
- post_request("#{PATH}/authenticate", request)
63
+ post_request('/v1/oauth/attach', request)
33
64
  end
34
65
 
35
- # Send a /v1/oauth/attach request.
66
+ # Authenticate a User given a `token`. This endpoint verifies that the user completed the OAuth flow by verifying that the token is valid and hasn't expired. To initiate a Stytch session for the user while authenticating their OAuth token, include `session_duration_minutes`; a session with the identity provider, e.g. Google or Facebook, will always be initiated upon successful authentication.
36
67
  #
37
- # Exactly one of user_id, session_token, or session_jwt is required.
38
- def attach(
39
- provider:,
40
- user_id: nil,
68
+ # == Parameters:
69
+ # token::
70
+ # The token to authenticate.
71
+ # The type of this field is +String+.
72
+ # session_token::
73
+ # Reuse an existing session instead of creating a new one. If you provide us with a `session_token`, then we'll update the session represented by this session token with this OAuth factor. If this `session_token` belongs to a different user than the OAuth token, the session_jwt will be ignored. This endpoint will error if both `session_token` and `session_jwt` are provided.
74
+ # The type of this field is nilable +String+.
75
+ # session_duration_minutes::
76
+ # Set the session lifetime to be this many minutes from now. This will start a new session if one doesn't already exist,
77
+ # returning both an opaque `session_token` and `session_jwt` for this session. Remember that the `session_jwt` will have a fixed lifetime of
78
+ # five minutes regardless of the underlying session duration, and will need to be refreshed over time.
79
+ #
80
+ # This value must be a minimum of 5 and a maximum of 527040 minutes (366 days).
81
+ #
82
+ # If a `session_token` or `session_jwt` is provided then a successful authentication will continue to extend the session this many minutes.
83
+ #
84
+ # If the `session_duration_minutes` parameter is not specified, a Stytch session will not be created.
85
+ # The type of this field is nilable +Integer+.
86
+ # session_jwt::
87
+ # Reuse an existing session instead of creating a new one. If you provide us with a `session_jwt`, then we'll update the session represented by this JWT with this OAuth factor. If this `session_jwt` belongs to a different user than the OAuth token, the session_jwt will be ignored. This endpoint will error if both `session_token` and `session_jwt` are provided.
88
+ # The type of this field is nilable +String+.
89
+ # session_custom_claims::
90
+ # Add a custom claims map to the Session being authenticated. Claims are only created if a Session is initialized by providing a value in `session_duration_minutes`. Claims will be included on the Session object and in the JWT. To update a key in an existing Session, supply a new value. To delete a key, supply a null value.
91
+ #
92
+ # Custom claims made with reserved claims ("iss", "sub", "aud", "exp", "nbf", "iat", "jti") will be ignored. Total custom claims size cannot exceed four kilobytes.
93
+ # The type of this field is nilable +object+.
94
+ # code_verifier::
95
+ # A base64url encoded one time secret used to validate that the request starts and ends on the same device.
96
+ # The type of this field is nilable +String+.
97
+ #
98
+ # == Returns:
99
+ # An object with the following fields:
100
+ # request_id::
101
+ # Globally unique UUID that is returned with every API call. This value is important to log for debugging purposes; we may ask for this value to help identify a specific API call when helping you debug an issue.
102
+ # The type of this field is +String+.
103
+ # user_id::
104
+ # The unique ID of the affected User.
105
+ # The type of this field is +String+.
106
+ # provider_subject::
107
+ # The unique identifier for the User within a given OAuth provider. Also commonly called the "sub" or "Subject field" in OAuth protocols.
108
+ # The type of this field is +String+.
109
+ # provider_type::
110
+ # Denotes the OAuth identity provider that the user has authenticated with, e.g. Google, Facebook, GitHub etc.
111
+ # The type of this field is +String+.
112
+ # session_token::
113
+ # A secret token for a given Stytch Session.
114
+ # The type of this field is +String+.
115
+ # session_jwt::
116
+ # The JSON Web Token (JWT) for a given Stytch Session.
117
+ # The type of this field is +String+.
118
+ # provider_values::
119
+ # The `provider_values` object lists relevant identifiers, values, and scopes for a given OAuth provider. For example this object will include a provider's `access_token` that you can use to access the provider's API for a given user.
120
+ #
121
+ # Note that these values will vary based on the OAuth provider in question, e.g. `id_token` is only returned by OIDC complaint identity providers.
122
+ # The type of this field is +ProviderValues+ (+object+).
123
+ # user::
124
+ # The `user` object affected by this API call. See the [Get user endpoint](https://stytch.com/docs/api/get-user) for complete response field details.
125
+ # The type of this field is +User+ (+object+).
126
+ # reset_sessions::
127
+ # Indicates if all other of the User's Sessions need to be reset. You should check this field if you aren't using Stytch's Session product. If you are using Stytch's Session product, we revoke the User's other sessions for you.
128
+ # The type of this field is +Boolean+.
129
+ # oauth_user_registration_id::
130
+ # The unique ID for an OAuth registration.
131
+ # The type of this field is +String+.
132
+ # status_code::
133
+ # The HTTP status code of the response. Stytch follows standard HTTP response status code patterns, e.g. 2XX values equate to success, 3XX values are redirects, 4XX are client errors, and 5XX are server errors.
134
+ # The type of this field is +Integer+.
135
+ # user_session::
136
+ # A `Session` object. For backwards compatibility reasons, the session from an OAuth authenticate call is labeled as `user_session`, but is otherwise just a standard stytch `Session` object.
137
+ #
138
+ # See [GET sessions](https://stytch.com/docs/api/session-get) for complete response fields.
139
+ #
140
+ # The type of this field is nilable +Session+ (+object+).
141
+ def authenticate(
142
+ token:,
41
143
  session_token: nil,
42
- session_jwt: nil
144
+ session_duration_minutes: nil,
145
+ session_jwt: nil,
146
+ session_custom_claims: nil,
147
+ code_verifier: nil
43
148
  )
44
149
  request = {
45
- provider: provider
150
+ token: token
46
151
  }
47
- request[:user_id] = user_id unless user_id.nil?
48
152
  request[:session_token] = session_token unless session_token.nil?
153
+ request[:session_duration_minutes] = session_duration_minutes unless session_duration_minutes.nil?
49
154
  request[:session_jwt] = session_jwt unless session_jwt.nil?
155
+ request[:session_custom_claims] = session_custom_claims unless session_custom_claims.nil?
156
+ request[:code_verifier] = code_verifier unless code_verifier.nil?
50
157
 
51
- post_request("#{PATH}/attach", request)
158
+ post_request('/v1/oauth/authenticate', request)
52
159
  end
53
160
  end
54
161
  end