@@ -31,19 +31,15 @@ import { SsoAccessTokenProvider } from './ssoAccessTokenProvider'
31
31
import { isClientFault } from '../../shared/errors'
32
32
import { DevSettings } from '../../shared/settings'
33
33
import { SdkError } from '@aws-sdk/types'
34
- import { HttpRequest , HttpResponse } from '@aws-sdk /protocol-http'
35
- import { StandardRetryStrategy , defaultRetryDecider } from '@aws-sdk /middleware-retry'
36
- import OidcClientPKCE from './oidcclientpkce '
34
+ import { HttpRequest , HttpResponse } from '@smithy /protocol-http'
35
+ import { StandardRetryStrategy , defaultRetryDecider } from '@smithy /middleware-retry'
36
+ import { AuthenticationFlow } from './model '
37
37
import { toSnakeCase } from '../../shared/utilities/textUtilities'
38
- import { Credentials , Service } from 'aws-sdk'
39
- import apiConfig = require( './service-2.json' )
40
- import { ServiceOptions } from '../../shared/awsClientBuilder'
41
- import { ClientRegistration } from './model'
42
38
43
39
export class OidcClient {
44
40
public constructor ( private readonly client : SSOOIDC , private readonly clock : { Date : typeof Date } ) { }
45
41
46
- public async registerClient ( request : RegisterClientRequest ) {
42
+ public async registerClient ( request : RegisterClientRequest , flow ?: AuthenticationFlow ) {
47
43
const response = await this . client . registerClient ( request )
48
44
assertHasProps ( response , 'clientId' , 'clientSecret' , 'clientSecretExpiresAt' )
49
45
@@ -52,6 +48,7 @@ export class OidcClient {
52
48
clientId : response . clientId ,
53
49
clientSecret : response . clientSecret ,
54
50
expiresAt : new this . clock . Date ( response . clientSecretExpiresAt * 1000 ) ,
51
+ ...( flow ? { flow } : { } ) ,
55
52
}
56
53
}
57
54
@@ -66,6 +63,23 @@ export class OidcClient {
66
63
}
67
64
}
68
65
66
+ public async authorize ( request : {
67
+ responseType : string
68
+ clientId : string
69
+ redirectUri : string
70
+ scopes : string [ ]
71
+ state : string
72
+ codeChallenge : string
73
+ codeChallengeMethod : string
74
+ } ) {
75
+ // aws sdk doesn't convert to url params until right before you make the request, so we have to do
76
+ // it manually ahead of time
77
+ const params = toSnakeCase ( request )
78
+ const searchParams = new URLSearchParams ( params ) . toString ( )
79
+ const region = await this . client . config . region ( )
80
+ return `https://oidc.${ region } .amazonaws.com/authorize?${ searchParams } `
81
+ }
82
+
69
83
public async createToken ( request : CreateTokenRequest ) {
70
84
const response = await this . client . createToken ( request as CreateTokenRequest )
71
85
assertHasProps ( response , 'accessToken' , 'expiresIn' )
@@ -100,79 +114,6 @@ export class OidcClient {
100
114
}
101
115
}
102
116
103
- export class OidcClientV2 {
104
- public constructor ( private readonly region : string , private readonly clock : { Date : typeof Date } ) { }
105
-
106
- /**
107
- * TODO remove this when the real client gets created.
108
- *
109
- * Creating a new client is required because the old sdk seems to drop unknown parameters from requests
110
- */
111
- private async createNewClient ( ) {
112
- return ( await globals . sdkClientBuilder . createAwsService (
113
- Service ,
114
- {
115
- apiConfig,
116
- region : this . region ,
117
- credentials : new Credentials ( { accessKeyId : 'xxx' , secretAccessKey : 'xxx' } ) ,
118
- } as ServiceOptions ,
119
- undefined
120
- ) ) as OidcClientPKCE
121
- }
122
-
123
- public async registerClient ( request : OidcClientPKCE . RegisterClientRequest ) : Promise < ClientRegistration > {
124
- const client = await this . createNewClient ( )
125
- const response = await client . makeUnauthenticatedRequest ( 'registerClient' , request ) . promise ( )
126
- assertHasProps ( response , 'clientId' , 'clientSecret' , 'clientSecretExpiresAt' )
127
-
128
- return {
129
- scopes : request . scopes ,
130
- clientId : response . clientId ,
131
- clientSecret : response . clientSecret ,
132
- expiresAt : new this . clock . Date ( response . clientSecretExpiresAt * 1000 ) ,
133
- flow : 'auth code' ,
134
- }
135
- }
136
-
137
- public async authorize ( request : OidcClientPKCE . AuthorizeRequest ) {
138
- // aws sdk doesn't convert to url params until right before you make the request, so we have to do
139
- // it manually ahead of time
140
- const params = toSnakeCase ( request )
141
- const searchParams = new URLSearchParams ( params ) . toString ( )
142
- return `https://oidc.${ this . region } .amazonaws.com/authorize?${ searchParams } `
143
- }
144
-
145
- public async startDeviceAuthorization ( request : StartDeviceAuthorizationRequest ) : Promise < {
146
- expiresAt : Date
147
- interval : number | undefined
148
- deviceCode : string
149
- userCode : string
150
- verificationUri : string
151
- } > {
152
- throw new Error ( 'OidcClientV2 does not support device authorization' )
153
- }
154
-
155
- public async createToken ( request : OidcClientPKCE . CreateTokenRequest ) : Promise < {
156
- accessToken : string
157
- expiresAt : Date
158
- tokenType ?: string | undefined
159
- refreshToken ?: string | undefined
160
- } > {
161
- const client = await this . createNewClient ( )
162
- const response = await client . makeUnauthenticatedRequest ( 'createToken' , request ) . promise ( )
163
- assertHasProps ( response , 'accessToken' , 'expiresIn' )
164
-
165
- return {
166
- ...selectFrom ( response , 'accessToken' , 'refreshToken' , 'tokenType' ) ,
167
- expiresAt : new this . clock . Date ( response . expiresIn * 1000 + this . clock . Date . now ( ) ) ,
168
- }
169
- }
170
-
171
- public static create ( region : string ) {
172
- return new this ( region , globals . clock )
173
- }
174
- }
175
-
176
117
type OmittedProps = 'accessToken' | 'nextToken'
177
118
type ExtractOverload < T , U > = T extends {
178
119
( ...args : infer P1 ) : infer R1
0 commit comments