@@ -73,7 +73,9 @@ const getLoginHint = (userId: string, domain: string): string => {
73
73
/**
74
74
* Options for the authorize request.
75
75
*/
76
- export type AuthorizeOptions = {
76
+ export interface AuthorizeOptions <
77
+ TAuthorizationDetails extends AuthorizationDetails = AuthorizationDetails
78
+ > {
77
79
/**
78
80
* A human-readable string intended to be displayed on both the device calling /bc-authorize and the user’s authentication device.
79
81
*/
@@ -102,18 +104,28 @@ export type AuthorizeOptions = {
102
104
* Optional authorization details to use Rich Authorization Requests (RAR).
103
105
* @see https://auth0.com/docs/get-started/apis/configure-rich-authorization-requests
104
106
*/
105
- authorization_details ?: string ;
106
- } & Record < string , string > ;
107
+ authorization_details ?: string | TAuthorizationDetails [ ] ;
108
+
109
+ [ key : string ] : unknown ;
110
+ }
107
111
108
112
type AuthorizeRequest = Omit < AuthorizeOptions , 'userId' > &
109
113
AuthorizeCredentialsPartial & {
110
114
login_hint : string ;
111
- } ;
115
+ authorization_details ?: string ;
116
+ } & Record < string , string > ;
117
+
118
+ interface AuthorizationDetails {
119
+ readonly type : string ;
120
+ readonly [ parameter : string ] : unknown ;
121
+ }
112
122
113
123
/**
114
124
* The response from the token endpoint.
115
125
*/
116
- export type TokenResponse = {
126
+ export interface TokenResponse <
127
+ TAuthorizationDetails extends AuthorizationDetails = AuthorizationDetails
128
+ > {
117
129
/**
118
130
* The access token.
119
131
*/
@@ -142,8 +154,8 @@ export type TokenResponse = {
142
154
* Optional authorization details when using Rich Authorization Requests (RAR).
143
155
* @see https://auth0.com/docs/get-started/apis/configure-rich-authorization-requests
144
156
*/
145
- authorization_details ?: string ;
146
- } ;
157
+ authorization_details ?: TAuthorizationDetails [ ] ;
158
+ }
147
159
148
160
/**
149
161
* Options for the token request.
@@ -185,8 +197,18 @@ export class Backchannel extends BaseAuthAPI implements IBackchannel {
185
197
* @throws {Error } - If the request fails.
186
198
*/
187
199
async authorize ( { userId, ...options } : AuthorizeOptions ) : Promise < AuthorizeResponse > {
200
+ const { authorization_details, ...authorizeOptions } = options ;
201
+
202
+ if ( authorization_details ) {
203
+ // Convert to string if not already
204
+ authorizeOptions . authorization_details =
205
+ typeof authorization_details !== 'string'
206
+ ? JSON . stringify ( authorization_details )
207
+ : authorization_details ;
208
+ }
209
+
188
210
const body : AuthorizeRequest = {
189
- ...options ,
211
+ ...authorizeOptions ,
190
212
login_hint : getLoginHint ( userId , this . domain ) ,
191
213
client_id : this . clientId ,
192
214
} ;
@@ -239,7 +261,9 @@ export class Backchannel extends BaseAuthAPI implements IBackchannel {
239
261
* }
240
262
* ```
241
263
*/
242
- async backchannelGrant ( { auth_req_id } : TokenOptions ) : Promise < TokenResponse > {
264
+ async backchannelGrant <
265
+ TAuthorizationDetails extends AuthorizationDetails = AuthorizationDetails
266
+ > ( { auth_req_id } : TokenOptions ) : Promise < TokenResponse < TAuthorizationDetails > > {
243
267
const body : TokenRequestBody = {
244
268
client_id : this . clientId ,
245
269
auth_req_id,
@@ -258,7 +282,8 @@ export class Backchannel extends BaseAuthAPI implements IBackchannel {
258
282
{ }
259
283
) ;
260
284
261
- const r : JSONApiResponse < TokenResponse > = await JSONApiResponse . fromResponse ( response ) ;
285
+ const r : JSONApiResponse < TokenResponse < TAuthorizationDetails > > =
286
+ await JSONApiResponse . fromResponse ( response ) ;
262
287
return r . data ;
263
288
}
264
289
}
0 commit comments