@@ -30,7 +30,7 @@ interface HttpAuthSchemeMiddlewareOptions<
3030 TConfig extends object ,
3131 TContext extends HandlerExecutionContext ,
3232 TParameters extends HttpAuthSchemeParameters ,
33- TInput extends object
33+ TInput extends object ,
3434> {
3535 httpAuthSchemeParametersProvider : HttpAuthSchemeParametersProvider < TConfig , TContext , TParameters , TInput > ;
3636 identityProviderConfigProvider : ( config : TConfig ) => Promise < IdentityProviderConfig > ;
@@ -65,50 +65,51 @@ function convertHttpAuthSchemesToMap(httpAuthSchemes: HttpAuthScheme[]): Map<Htt
6565/**
6666 * @internal
6767 */
68- export const httpAuthSchemeMiddleware = <
69- TInput extends object ,
70- Output extends object ,
71- TConfig extends object ,
72- TContext extends HttpAuthSchemeMiddlewareHandlerExecutionContext ,
73- TParameters extends HttpAuthSchemeParameters
74- > (
75- config : TConfig & PreviouslyResolved < TParameters > ,
76- mwOptions : HttpAuthSchemeMiddlewareOptions < TConfig , TContext , TParameters , TInput >
77- ) : SerializeMiddleware < TInput , Output > => (
78- next : SerializeHandler < TInput , Output > ,
79- context : HttpAuthSchemeMiddlewareHandlerExecutionContext
80- ) : SerializeHandler < TInput , Output > => async (
81- args : SerializeHandlerArguments < TInput >
82- ) : Promise < SerializeHandlerOutput < Output > > => {
83- const options = config . httpAuthSchemeProvider (
84- await mwOptions . httpAuthSchemeParametersProvider ( config , context as TContext , args . input )
85- ) ;
86- const authSchemes = convertHttpAuthSchemesToMap ( config . httpAuthSchemes ) ;
87- const smithyContext : HttpAuthSchemeMiddlewareSmithyContext = getSmithyContext ( context ) ;
88- const failureReasons = [ ] ;
89- for ( const option of options ) {
90- const scheme = authSchemes . get ( option . schemeId ) ;
91- if ( ! scheme ) {
92- failureReasons . push ( `HttpAuthScheme \`${ option . schemeId } \` was not enabled for this service.` ) ;
93- continue ;
68+ export const httpAuthSchemeMiddleware =
69+ <
70+ TInput extends object ,
71+ Output extends object ,
72+ TConfig extends object ,
73+ TContext extends HttpAuthSchemeMiddlewareHandlerExecutionContext ,
74+ TParameters extends HttpAuthSchemeParameters ,
75+ > (
76+ config : TConfig & PreviouslyResolved < TParameters > ,
77+ mwOptions : HttpAuthSchemeMiddlewareOptions < TConfig , TContext , TParameters , TInput >
78+ ) : SerializeMiddleware < TInput , Output > =>
79+ (
80+ next : SerializeHandler < TInput , Output > ,
81+ context : HttpAuthSchemeMiddlewareHandlerExecutionContext
82+ ) : SerializeHandler < TInput , Output > =>
83+ async ( args : SerializeHandlerArguments < TInput > ) : Promise < SerializeHandlerOutput < Output > > => {
84+ const options = config . httpAuthSchemeProvider (
85+ await mwOptions . httpAuthSchemeParametersProvider ( config , context as TContext , args . input )
86+ ) ;
87+ const authSchemes = convertHttpAuthSchemesToMap ( config . httpAuthSchemes ) ;
88+ const smithyContext : HttpAuthSchemeMiddlewareSmithyContext = getSmithyContext ( context ) ;
89+ const failureReasons = [ ] ;
90+ for ( const option of options ) {
91+ const scheme = authSchemes . get ( option . schemeId ) ;
92+ if ( ! scheme ) {
93+ failureReasons . push ( `HttpAuthScheme \`${ option . schemeId } \` was not enabled for this service.` ) ;
94+ continue ;
95+ }
96+ const identityProvider = scheme . identityProvider ( await mwOptions . identityProviderConfigProvider ( config ) ) ;
97+ if ( ! identityProvider ) {
98+ failureReasons . push ( `HttpAuthScheme \`${ option . schemeId } \` did not have an IdentityProvider configured.` ) ;
99+ continue ;
100+ }
101+ const { identityProperties = { } , signingProperties = { } } = option . propertiesExtractor ?.( config , context ) || { } ;
102+ option . identityProperties = Object . assign ( option . identityProperties || { } , identityProperties ) ;
103+ option . signingProperties = Object . assign ( option . signingProperties || { } , signingProperties ) ;
104+ smithyContext . selectedHttpAuthScheme = {
105+ httpAuthOption : option ,
106+ identity : await identityProvider ( option . identityProperties ) ,
107+ signer : scheme . signer ,
108+ } ;
109+ break ;
94110 }
95- const identityProvider = scheme . identityProvider ( await mwOptions . identityProviderConfigProvider ( config ) ) ;
96- if ( ! identityProvider ) {
97- failureReasons . push ( `HttpAuthScheme \`${ option . schemeId } \` did not have an IdentityProvider configured.` ) ;
98- continue ;
111+ if ( ! smithyContext . selectedHttpAuthScheme ) {
112+ throw new Error ( failureReasons . join ( "\n" ) ) ;
99113 }
100- const { identityProperties = { } , signingProperties = { } } = option . propertiesExtractor ?.( config , context ) || { } ;
101- option . identityProperties = Object . assign ( option . identityProperties || { } , identityProperties ) ;
102- option . signingProperties = Object . assign ( option . signingProperties || { } , signingProperties ) ;
103- smithyContext . selectedHttpAuthScheme = {
104- httpAuthOption : option ,
105- identity : await identityProvider ( option . identityProperties ) ,
106- signer : scheme . signer ,
107- } ;
108- break ;
109- }
110- if ( ! smithyContext . selectedHttpAuthScheme ) {
111- throw new Error ( failureReasons . join ( "\n" ) ) ;
112- }
113- return next ( args ) ;
114- } ;
114+ return next ( args ) ;
115+ } ;
0 commit comments