Skip to content

Commit 5968a47

Browse files
feat: add MFA OTP support for IAM members (#1727)
Co-authored-by: philibeaux <[email protected]>
1 parent 524aa5c commit 5968a47

File tree

5 files changed

+133
-0
lines changed

5 files changed

+133
-0
lines changed

packages/clients/src/api/iam/v1alpha1/api.gen.ts

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import {
2929
marshalUpdateUserPasswordRequest,
3030
marshalUpdateUserRequest,
3131
marshalUpdateUserUsernameRequest,
32+
marshalValidateUserMFAOTPRequest,
3233
unmarshalAPIKey,
3334
unmarshalApplication,
3435
unmarshalEncodedJWT,
@@ -47,12 +48,14 @@ import {
4748
unmarshalListSSHKeysResponse,
4849
unmarshalListUsersResponse,
4950
unmarshalLog,
51+
unmarshalMFAOTP,
5052
unmarshalOrganizationSecuritySettings,
5153
unmarshalPolicy,
5254
unmarshalQuotum,
5355
unmarshalSSHKey,
5456
unmarshalSetRulesResponse,
5557
unmarshalUser,
58+
unmarshalValidateUserMFAOTPResponse,
5659
} from './marshalling.gen'
5760
import type {
5861
APIKey,
@@ -66,13 +69,15 @@ import type {
6669
CreateJWTRequest,
6770
CreatePolicyRequest,
6871
CreateSSHKeyRequest,
72+
CreateUserMFAOTPRequest,
6973
CreateUserRequest,
7074
DeleteAPIKeyRequest,
7175
DeleteApplicationRequest,
7276
DeleteGroupRequest,
7377
DeleteJWTRequest,
7478
DeletePolicyRequest,
7579
DeleteSSHKeyRequest,
80+
DeleteUserMFAOTPRequest,
7681
DeleteUserRequest,
7782
EncodedJWT,
7883
GetAPIKeyRequest,
@@ -113,6 +118,7 @@ import type {
113118
ListUsersResponse,
114119
LockUserRequest,
115120
Log,
121+
MFAOTP,
116122
OrganizationSecuritySettings,
117123
Policy,
118124
Quotum,
@@ -132,6 +138,8 @@ import type {
132138
UpdateUserRequest,
133139
UpdateUserUsernameRequest,
134140
User,
141+
ValidateUserMFAOTPRequest,
142+
ValidateUserMFAOTPResponse,
135143
} from './types.gen'
136144

137145
const jsonContentHeaders = {
@@ -397,6 +405,58 @@ export class API extends ParentAPI {
397405
unmarshalUser,
398406
)
399407

408+
/**
409+
* Create a MFA OTP. Private Beta feature.. Create a MFA OTP. Private Beta
410+
* feature.
411+
*
412+
* @param request - The request {@link CreateUserMFAOTPRequest}
413+
* @returns A Promise of MFAOTP
414+
*/
415+
createUserMFAOTP = (request: Readonly<CreateUserMFAOTPRequest>) =>
416+
this.client.fetch<MFAOTP>(
417+
{
418+
body: '{}',
419+
headers: jsonContentHeaders,
420+
method: 'POST',
421+
path: `/iam/v1alpha1/users/${validatePathParam('userId', request.userId)}/mfa-otp`,
422+
},
423+
unmarshalMFAOTP,
424+
)
425+
426+
/**
427+
* Validate a MFA OTP. Private Beta feature.. Validate a MFA OTP. Private Beta
428+
* feature.
429+
*
430+
* @param request - The request {@link ValidateUserMFAOTPRequest}
431+
* @returns A Promise of ValidateUserMFAOTPResponse
432+
*/
433+
validateUserMFAOTP = (request: Readonly<ValidateUserMFAOTPRequest>) =>
434+
this.client.fetch<ValidateUserMFAOTPResponse>(
435+
{
436+
body: JSON.stringify(
437+
marshalValidateUserMFAOTPRequest(request, this.client.settings),
438+
),
439+
headers: jsonContentHeaders,
440+
method: 'POST',
441+
path: `/iam/v1alpha1/users/${validatePathParam('userId', request.userId)}/validate-mfa-otp`,
442+
},
443+
unmarshalValidateUserMFAOTPResponse,
444+
)
445+
446+
/**
447+
* Delete a MFA OTP. Private Beta feature.. Delete a MFA OTP. Private Beta
448+
* feature.
449+
*
450+
* @param request - The request {@link DeleteUserMFAOTPRequest}
451+
*/
452+
deleteUserMFAOTP = (request: Readonly<DeleteUserMFAOTPRequest>) =>
453+
this.client.fetch<void>({
454+
body: '{}',
455+
headers: jsonContentHeaders,
456+
method: 'DELETE',
457+
path: `/iam/v1alpha1/users/${validatePathParam('userId', request.userId)}/mfa-otp`,
458+
})
459+
400460
/**
401461
* Lock a member. Lock a member. A locked member cannot log in or use API keys
402462
* until the locked status is removed. Private Beta feature.

packages/clients/src/api/iam/v1alpha1/index.gen.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ export type {
1414
CreateJWTRequest,
1515
CreatePolicyRequest,
1616
CreateSSHKeyRequest,
17+
CreateUserMFAOTPRequest,
1718
CreateUserRequest,
1819
CreateUserRequestMember,
1920
DeleteAPIKeyRequest,
@@ -22,6 +23,7 @@ export type {
2223
DeleteJWTRequest,
2324
DeletePolicyRequest,
2425
DeleteSSHKeyRequest,
26+
DeleteUserMFAOTPRequest,
2527
DeleteUserRequest,
2628
EncodedJWT,
2729
GetAPIKeyRequest,
@@ -76,6 +78,7 @@ export type {
7678
Log,
7779
LogAction,
7880
LogResourceType,
81+
MFAOTP,
7982
OrganizationSecuritySettings,
8083
PermissionSet,
8184
PermissionSetScopeType,
@@ -101,5 +104,7 @@ export type {
101104
User,
102105
UserStatus,
103106
UserType,
107+
ValidateUserMFAOTPRequest,
108+
ValidateUserMFAOTPResponse,
104109
} from './types.gen'
105110
export * as ValidationRules from './validation-rules.gen'

packages/clients/src/api/iam/v1alpha1/marshalling.gen.ts

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ import type {
3838
ListSSHKeysResponse,
3939
ListUsersResponse,
4040
Log,
41+
MFAOTP,
4142
OrganizationSecuritySettings,
4243
PermissionSet,
4344
Policy,
@@ -59,6 +60,8 @@ import type {
5960
UpdateUserRequest,
6061
UpdateUserUsernameRequest,
6162
User,
63+
ValidateUserMFAOTPRequest,
64+
ValidateUserMFAOTPResponse,
6265
} from './types.gen'
6366

6467
export const unmarshalJWT = (data: unknown): JWT => {
@@ -506,6 +509,18 @@ export const unmarshalListUsersResponse = (
506509
} as ListUsersResponse
507510
}
508511

512+
export const unmarshalMFAOTP = (data: unknown): MFAOTP => {
513+
if (!isJSONObject(data)) {
514+
throw new TypeError(
515+
`Unmarshalling the type 'MFAOTP' failed as data isn't a dictionary.`,
516+
)
517+
}
518+
519+
return {
520+
secret: data.secret,
521+
} as MFAOTP
522+
}
523+
509524
export const unmarshalOrganizationSecuritySettings = (
510525
data: unknown,
511526
): OrganizationSecuritySettings => {
@@ -534,6 +549,20 @@ export const unmarshalSetRulesResponse = (data: unknown): SetRulesResponse => {
534549
} as SetRulesResponse
535550
}
536551

552+
export const unmarshalValidateUserMFAOTPResponse = (
553+
data: unknown,
554+
): ValidateUserMFAOTPResponse => {
555+
if (!isJSONObject(data)) {
556+
throw new TypeError(
557+
`Unmarshalling the type 'ValidateUserMFAOTPResponse' failed as data isn't a dictionary.`,
558+
)
559+
}
560+
561+
return {
562+
recoveryCodes: data.recovery_codes,
563+
} as ValidateUserMFAOTPResponse
564+
}
565+
537566
export const marshalAddGroupMemberRequest = (
538567
request: AddGroupMemberRequest,
539568
defaults: DefaultValues,
@@ -768,3 +797,10 @@ export const marshalUpdateUserUsernameRequest = (
768797
): Record<string, unknown> => ({
769798
username: request.username,
770799
})
800+
801+
export const marshalValidateUserMFAOTPRequest = (
802+
request: ValidateUserMFAOTPRequest,
803+
defaults: DefaultValues,
804+
): Record<string, unknown> => ({
805+
one_time_password: request.oneTimePassword,
806+
})

packages/clients/src/api/iam/v1alpha1/types.gen.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -586,6 +586,11 @@ export type CreateSSHKeyRequest = {
586586
projectId?: string
587587
}
588588

589+
export type CreateUserMFAOTPRequest = {
590+
/** User ID of the MFA OTP. */
591+
userId: string
592+
}
593+
589594
export type CreateUserRequest = {
590595
/** ID of the Organization. */
591596
organizationId?: string
@@ -634,6 +639,11 @@ export type DeleteSSHKeyRequest = {
634639
sshKeyId: string
635640
}
636641

642+
export type DeleteUserMFAOTPRequest = {
643+
/** User ID of the MFA OTP. */
644+
userId: string
645+
}
646+
637647
export type DeleteUserRequest = {
638648
/** ID of the user to delete. */
639649
userId: string
@@ -995,6 +1005,10 @@ export type LockUserRequest = {
9951005
userId: string
9961006
}
9971007

1008+
export interface MFAOTP {
1009+
secret: string
1010+
}
1011+
9981012
export interface OrganizationSecuritySettings {
9991013
/** Defines whether password renewal is enforced during first login. */
10001014
enforcePasswordRenewal: boolean
@@ -1158,3 +1172,15 @@ export type UpdateUserUsernameRequest = {
11581172
/** The new username. */
11591173
username: string
11601174
}
1175+
1176+
export type ValidateUserMFAOTPRequest = {
1177+
/** User ID of the MFA OTP. */
1178+
userId: string
1179+
/** A password generated using the OTP. */
1180+
oneTimePassword: string
1181+
}
1182+
1183+
export interface ValidateUserMFAOTPResponse {
1184+
/** List of recovery codes usable for this OTP method. */
1185+
recoveryCodes: string[]
1186+
}

packages/clients/src/api/iam/v1alpha1/validation-rules.gen.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,3 +269,9 @@ export const UpdateUserUsernameRequest = {
269269
pattern: /^[a-zA-Z0-9._-]+$/,
270270
},
271271
}
272+
273+
export const ValidateUserMFAOTPRequest = {
274+
oneTimePassword: {
275+
pattern: /^[0-9]{6}$/,
276+
},
277+
}

0 commit comments

Comments
 (0)