11import { addAzureParams , AZURE_BASE_URL } from '../../../client-side-encryption/providers/azure' ;
22import { MongoAzureError } from '../../../error' ;
33import { get } from '../../../utils' ;
4- import type { MongoCredentials } from '../mongo_credentials' ;
5- import { type AccessToken , MachineWorkflow } from './machine_workflow' ;
6- import { type TokenCache } from './token_cache' ;
4+ import type { OIDCCallbackParams , OIDCResponse } from '../mongodb_oidc' ;
75
86/** Azure request headers. */
97const AZURE_HEADERS = Object . freeze ( { Metadata : 'true' , Accept : 'application/json' } ) ;
@@ -17,39 +15,27 @@ const TOKEN_RESOURCE_MISSING_ERROR =
1715 'TOKEN_RESOURCE must be set in the auth mechanism properties when ENVIRONMENT is azure.' ;
1816
1917/**
20- * Device workflow implementation for Azure .
21- *
22- * @internal
18+ * The callback function to be used in the automated callback workflow .
19+ * @param params - The OIDC callback parameters.
20+ * @returns The OIDC response.
2321 */
24- export class AzureMachineWorkflow extends MachineWorkflow {
25- /**
26- * Instantiate the machine workflow.
27- */
28- constructor ( cache : TokenCache ) {
29- super ( cache ) ;
22+ export async function callback ( params : OIDCCallbackParams ) : Promise < OIDCResponse > {
23+ const tokenAudience = params . tokenAudience ;
24+ const username = params . username ;
25+ if ( ! tokenAudience ) {
26+ throw new MongoAzureError ( TOKEN_RESOURCE_MISSING_ERROR ) ;
3027 }
31-
32- /**
33- * Get the token from the environment.
34- */
35- async getToken ( credentials ?: MongoCredentials ) : Promise < AccessToken > {
36- const tokenAudience = credentials ?. mechanismProperties . TOKEN_RESOURCE ;
37- const username = credentials ?. username ;
38- if ( ! tokenAudience ) {
39- throw new MongoAzureError ( TOKEN_RESOURCE_MISSING_ERROR ) ;
40- }
41- const response = await getAzureTokenData ( tokenAudience , username ) ;
42- if ( ! isEndpointResultValid ( response ) ) {
43- throw new MongoAzureError ( ENDPOINT_RESULT_ERROR ) ;
44- }
45- return response ;
28+ const response = await getAzureTokenData ( tokenAudience , username ) ;
29+ if ( ! isEndpointResultValid ( response ) ) {
30+ throw new MongoAzureError ( ENDPOINT_RESULT_ERROR ) ;
4631 }
32+ return response ;
4733}
4834
4935/**
5036 * Hit the Azure endpoint to get the token data.
5137 */
52- async function getAzureTokenData ( tokenAudience : string , username ?: string ) : Promise < AccessToken > {
38+ async function getAzureTokenData ( tokenAudience : string , username ?: string ) : Promise < OIDCResponse > {
5339 const url = new URL ( AZURE_BASE_URL ) ;
5440 addAzureParams ( url , tokenAudience , username ) ;
5541 const response = await get ( url , {
@@ -62,8 +48,8 @@ async function getAzureTokenData(tokenAudience: string, username?: string): Prom
6248 }
6349 const result = JSON . parse ( response . body ) ;
6450 return {
65- access_token : result . access_token ,
66- expires_in : Number ( result . expires_in )
51+ accessToken : result . access_token ,
52+ expiresInSeconds : Number ( result . expires_in )
6753 } ;
6854}
6955
0 commit comments