Commit 3a84cbd5 authored by Ahmet Turan Koçak's avatar Ahmet Turan Koçak
Browse files

Initial commit

parents
{"version":3,"file":"ICachePlugin.d.ts","sourceRoot":"","sources":["../../../src/cache/interface/ICachePlugin.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,iBAAiB,EAAE,MAAM,kCAAkC,CAAC;AAErE,MAAM,WAAW,YAAY;IACzB,iBAAiB,EAAE,CAAC,iBAAiB,EAAE,iBAAiB,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IAC3E,gBAAgB,EAAE,CAAC,iBAAiB,EAAE,iBAAiB,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;CAC7E"}
\ No newline at end of file
{"version":3,"file":"ISerializableTokenCache.d.ts","sourceRoot":"","sources":["../../../src/cache/interface/ISerializableTokenCache.ts"],"names":[],"mappings":"AAKA,MAAM,WAAW,uBAAuB;IACpC,WAAW,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;IACrC,SAAS,EAAE,MAAM,MAAM,CAAC;CAC3B"}
\ No newline at end of file
{"version":3,"file":"TokenCacheContext.d.ts","sourceRoot":"","sources":["../../../src/cache/persistence/TokenCacheContext.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,uBAAuB,EAAE,MAAM,sCAAsC,CAAC;AAE/E;;;GAGG,CAAA,qBAAa,iBAAiB;IAC7B;;OAEG;IACH,UAAU,EAAE,OAAO,CAAC;IACpB;;OAEG;IACH,KAAK,EAAE,uBAAuB,CAAC;gBAEnB,UAAU,EAAE,uBAAuB,EAAE,UAAU,EAAE,OAAO;IAKpE;;OAEG;IACH,IAAI,eAAe,IAAI,OAAO,CAE7B;IAED;;OAEG;IACH,IAAI,UAAU,IAAI,uBAAuB,CAExC;CACJ"}
\ No newline at end of file
/*! @azure/msal-common v9.0.1 2022-12-07 */
'use strict';
/*
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License.
*/
/**
* This class instance helps track the memory changes facilitating
* decisions to read from and write to the persistent cache
*/ var TokenCacheContext = /** @class */ (function () {
function TokenCacheContext(tokenCache, hasChanged) {
this.cache = tokenCache;
this.hasChanged = hasChanged;
}
Object.defineProperty(TokenCacheContext.prototype, "cacheHasChanged", {
/**
* boolean which indicates the changes in cache
*/
get: function () {
return this.hasChanged;
},
enumerable: false,
configurable: true
});
Object.defineProperty(TokenCacheContext.prototype, "tokenCache", {
/**
* function to retrieve the token cache
*/
get: function () {
return this.cache;
},
enumerable: false,
configurable: true
});
return TokenCacheContext;
}());
export { TokenCacheContext };
//# sourceMappingURL=TokenCacheContext.js.map
{"version":3,"file":"TokenCacheContext.js","sources":["../../../src/cache/persistence/TokenCacheContext.ts"],"sourcesContent":["/*\n * Copyright (c) Microsoft Corporation. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { ISerializableTokenCache } from \"../interface/ISerializableTokenCache\";\n\n/**\n * This class instance helps track the memory changes facilitating\n * decisions to read from and write to the persistent cache\n */export class TokenCacheContext {\n /**\n * boolean indicating cache change\n */\n hasChanged: boolean;\n /**\n * serializable token cache interface\n */\n cache: ISerializableTokenCache;\n\n constructor(tokenCache: ISerializableTokenCache, hasChanged: boolean) {\n this.cache = tokenCache;\n this.hasChanged = hasChanged;\n }\n\n /**\n * boolean which indicates the changes in cache\n */\n get cacheHasChanged(): boolean {\n return this.hasChanged;\n }\n\n /**\n * function to retrieve the token cache\n */\n get tokenCache(): ISerializableTokenCache {\n return this.cache;\n }\n}\n"],"names":[],"mappings":";;AAAA;;;AAGG;AAIH;;;IAGG,IAAA,iBAAA,kBAAA,YAAA;IAUC,SAAY,iBAAA,CAAA,UAAmC,EAAE,UAAmB,EAAA;AAChE,QAAA,IAAI,CAAC,KAAK,GAAG,UAAU,CAAC;AACxB,QAAA,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;KAChC;AAKD,IAAA,MAAA,CAAA,cAAA,CAAI,iBAAe,CAAA,SAAA,EAAA,iBAAA,EAAA;AAHnB;;AAEG;AACH,QAAA,GAAA,EAAA,YAAA;YACI,OAAO,IAAI,CAAC,UAAU,CAAC;SAC1B;;;AAAA,KAAA,CAAA,CAAA;AAKD,IAAA,MAAA,CAAA,cAAA,CAAI,iBAAU,CAAA,SAAA,EAAA,YAAA,EAAA;AAHd;;AAEG;AACH,QAAA,GAAA,EAAA,YAAA;YACI,OAAO,IAAI,CAAC,KAAK,CAAC;SACrB;;;AAAA,KAAA,CAAA,CAAA;IACL,OAAC,iBAAA,CAAA;AAAD,CAAC,EAAA;;;;"}
\ No newline at end of file
import { AccountEntity } from "../entities/AccountEntity";
import { IdTokenEntity } from "../entities/IdTokenEntity";
import { AccessTokenEntity } from "../entities/AccessTokenEntity";
import { RefreshTokenEntity } from "../entities/RefreshTokenEntity";
import { AppMetadataEntity } from "../entities/AppMetadataEntity";
import { ServerTelemetryEntity } from "../entities/ServerTelemetryEntity";
import { ThrottlingEntity } from "../entities/ThrottlingEntity";
import { AuthorityMetadataEntity } from "../entities/AuthorityMetadataEntity";
import { AuthenticationScheme } from "../../utils/Constants";
export declare type AccountCache = Record<string, AccountEntity>;
export declare type IdTokenCache = Record<string, IdTokenEntity>;
export declare type AccessTokenCache = Record<string, AccessTokenEntity>;
export declare type RefreshTokenCache = Record<string, RefreshTokenEntity>;
export declare type AppMetadataCache = Record<string, AppMetadataEntity>;
export declare type CredentialCache = {
idTokens: IdTokenCache;
accessTokens: AccessTokenCache;
refreshTokens: RefreshTokenCache;
};
/**
* Object type of all accepted cache types
*/
export declare type ValidCacheType = AccountEntity | IdTokenEntity | AccessTokenEntity | RefreshTokenEntity | AppMetadataEntity | AuthorityMetadataEntity | ServerTelemetryEntity | ThrottlingEntity | string;
/**
* Object type of all credential types
*/
export declare type ValidCredentialType = IdTokenEntity | AccessTokenEntity | RefreshTokenEntity;
/**
* Account: <home_account_id>-<environment>-<realm*>
*/
export declare type AccountFilter = {
homeAccountId?: string;
environment?: string;
realm?: string;
nativeAccountId?: string;
};
/**
* Credential: <home_account_id*>-<environment>-<credential_type>-<client_id>-<realm*>-<target*>-<scheme*>
*/
export declare type CredentialFilter = {
homeAccountId?: string;
environment?: string;
credentialType?: string;
clientId?: string;
familyId?: string;
realm?: string;
target?: string;
userAssertionHash?: string;
tokenType?: AuthenticationScheme;
keyId?: string;
requestedClaimsHash?: string;
};
/**
* AppMetadata: appmetadata-<environment>-<client_id>
*/
export declare type AppMetadataFilter = {
environment?: string;
clientId?: string;
};
//# sourceMappingURL=CacheTypes.d.ts.map
\ No newline at end of file
{"version":3,"file":"CacheTypes.d.ts","sourceRoot":"","sources":["../../../src/cache/utils/CacheTypes.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAC;AAC1D,OAAO,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAC;AAC1D,OAAO,EAAE,iBAAiB,EAAE,MAAM,+BAA+B,CAAC;AAClE,OAAO,EAAE,kBAAkB,EAAE,MAAM,gCAAgC,CAAC;AACpE,OAAO,EAAE,iBAAiB,EAAE,MAAM,+BAA+B,CAAC;AAClE,OAAO,EAAE,qBAAqB,EAAE,MAAM,mCAAmC,CAAC;AAC1E,OAAO,EAAE,gBAAgB,EAAE,MAAM,8BAA8B,CAAC;AAChE,OAAO,EAAE,uBAAuB,EAAE,MAAM,qCAAqC,CAAC;AAC9E,OAAO,EAAE,oBAAoB,EAAE,MAAM,uBAAuB,CAAC;AAE7D,oBAAY,YAAY,GAAG,MAAM,CAAC,MAAM,EAAE,aAAa,CAAC,CAAC;AACzD,oBAAY,YAAY,GAAG,MAAM,CAAC,MAAM,EAAE,aAAa,CAAC,CAAC;AACzD,oBAAY,gBAAgB,GAAG,MAAM,CAAC,MAAM,EAAE,iBAAiB,CAAC,CAAC;AACjE,oBAAY,iBAAiB,GAAG,MAAM,CAAC,MAAM,EAAE,kBAAkB,CAAC,CAAC;AACnE,oBAAY,gBAAgB,GAAG,MAAM,CAAC,MAAM,EAAE,iBAAiB,CAAC,CAAC;AACjE,oBAAY,eAAe,GAAG;IAC1B,QAAQ,EAAE,YAAY,CAAC;IACvB,YAAY,EAAE,gBAAgB,CAAC;IAC/B,aAAa,EAAE,iBAAiB,CAAC;CACpC,CAAC;AAEF;;GAEG;AACH,oBAAY,cAAc,GAAG,aAAa,GAAG,aAAa,GAAG,iBAAiB,GAAG,kBAAkB,GAAG,iBAAiB,GAAG,uBAAuB,GAAG,qBAAqB,GAAG,gBAAgB,GAAG,MAAM,CAAC;AAEtM;;GAEG;AACH,oBAAY,mBAAmB,GAAG,aAAa,GAAG,iBAAiB,GAAG,kBAAkB,CAAC;AAEzF;;GAEG;AACH,oBAAY,aAAa,GAAG;IACxB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,eAAe,CAAC,EAAE,MAAM,CAAC;CAC5B,CAAC;AAEF;;GAEG;AACH,oBAAY,gBAAgB,GAAG;IAC3B,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,SAAS,CAAC,EAAE,oBAAoB,CAAC;IACjC,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,mBAAmB,CAAC,EAAE,MAAM,CAAC;CAChC,CAAC;AAEF;;GAEG;AACH,oBAAY,iBAAiB,GAAG;IAC5B,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,EAAE,MAAM,CAAC;CACrB,CAAC"}
\ No newline at end of file
import { BaseClient } from "./BaseClient";
import { CommonAuthorizationUrlRequest } from "../request/CommonAuthorizationUrlRequest";
import { CommonAuthorizationCodeRequest } from "../request/CommonAuthorizationCodeRequest";
import { ClientConfiguration } from "../config/ClientConfiguration";
import { AuthenticationResult } from "../response/AuthenticationResult";
import { CommonEndSessionRequest } from "../request/CommonEndSessionRequest";
import { AuthorizationCodePayload } from "../response/AuthorizationCodePayload";
/**
* Oauth2.0 Authorization Code client
*/
export declare class AuthorizationCodeClient extends BaseClient {
protected includeRedirectUri: boolean;
constructor(configuration: ClientConfiguration);
/**
* Creates the URL of the authorization request letting the user input credentials and consent to the
* application. The URL target the /authorize endpoint of the authority configured in the
* application object.
*
* Once the user inputs their credentials and consents, the authority will send a response to the redirect URI
* sent in the request and should contain an authorization code, which can then be used to acquire tokens via
* acquireToken(AuthorizationCodeRequest)
* @param request
*/
getAuthCodeUrl(request: CommonAuthorizationUrlRequest): Promise<string>;
/**
* API to acquire a token in exchange of 'authorization_code` acquired by the user in the first leg of the
* authorization_code_grant
* @param request
*/
acquireToken(request: CommonAuthorizationCodeRequest, authCodePayload?: AuthorizationCodePayload): Promise<AuthenticationResult>;
/**
* Handles the hash fragment response from public client code request. Returns a code response used by
* the client to exchange for a token in acquireToken.
* @param hashFragment
*/
handleFragmentResponse(hashFragment: string, cachedState: string): AuthorizationCodePayload;
/**
* Used to log out the current user, and redirect the user to the postLogoutRedirectUri.
* Default behaviour is to redirect the user to `window.location.href`.
* @param authorityUri
*/
getLogoutUri(logoutRequest: CommonEndSessionRequest): string;
/**
* Executes POST request to token endpoint
* @param authority
* @param request
*/
private executeTokenRequest;
/**
* Creates query string for the /token request
* @param request
*/
private createTokenQueryParameters;
/**
* Generates a map for all the params to be sent to the service
* @param request
*/
private createTokenRequestBody;
/**
* This API validates the `AuthorizationCodeUrlRequest` and creates a URL
* @param request
*/
private createAuthCodeUrlQueryString;
/**
* This API validates the `EndSessionRequest` and creates a URL
* @param request
*/
private createLogoutUrlQueryString;
/**
* Helper to get sid from account. Returns null if idTokenClaims are not present or sid is not present.
* @param account
*/
private extractAccountSid;
private extractLoginHint;
}
//# sourceMappingURL=AuthorizationCodeClient.d.ts.map
\ No newline at end of file
{"version":3,"file":"AuthorizationCodeClient.d.ts","sourceRoot":"","sources":["../../src/client/AuthorizationCodeClient.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC1C,OAAO,EAAE,6BAA6B,EAAE,MAAM,0CAA0C,CAAC;AACzF,OAAO,EAAE,8BAA8B,EAAE,MAAM,2CAA2C,CAAC;AAI3F,OAAO,EAAE,mBAAmB,EAAE,MAAM,+BAA+B,CAAC;AAIpE,OAAO,EAAE,oBAAoB,EAAE,MAAM,kCAAkC,CAAC;AAKxE,OAAO,EAAE,uBAAuB,EAAE,MAAM,oCAAoC,CAAC;AAG7E,OAAO,EAAE,wBAAwB,EAAE,MAAM,sCAAsC,CAAC;AAQhF;;GAEG;AACH,qBAAa,uBAAwB,SAAQ,UAAU;IAEnD,SAAS,CAAC,kBAAkB,EAAE,OAAO,CAAQ;gBAEjC,aAAa,EAAE,mBAAmB;IAI9C;;;;;;;;;OASG;IACG,cAAc,CAAC,OAAO,EAAE,6BAA6B,GAAG,OAAO,CAAC,MAAM,CAAC;IAM7E;;;;OAIG;IACG,YAAY,CAAC,OAAO,EAAE,8BAA8B,EAAE,eAAe,CAAC,EAAE,wBAAwB,GAAG,OAAO,CAAC,oBAAoB,CAAC;IAoCtI;;;;OAIG;IACH,sBAAsB,CAAC,YAAY,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,GAAG,wBAAwB;IAuB3F;;;;OAIG;IACH,YAAY,CAAC,aAAa,EAAE,uBAAuB,GAAG,MAAM;IAW5D;;;;OAIG;YACW,mBAAmB;IAiCjC;;;OAGG;IACH,OAAO,CAAC,0BAA0B;IAUlC;;;OAGG;YACW,sBAAsB;IAoHpC;;;OAGG;YACW,4BAA4B;IAiI1C;;;OAGG;IACH,OAAO,CAAC,0BAA0B;IA8BlC;;;OAGG;IACH,OAAO,CAAC,iBAAiB;IAIzB,OAAO,CAAC,gBAAgB;CAG3B"}
\ No newline at end of file
/*! @azure/msal-common v9.0.1 2022-12-07 */
'use strict';
import { __extends, __awaiter, __generator, __assign, __spreadArrays } from '../_virtual/_tslib.js';
import { BaseClient } from './BaseClient.js';
import { RequestParameterBuilder } from '../request/RequestParameterBuilder.js';
import { Separators, AADServerParamKeys, AuthenticationScheme, GrantType, PromptValue, HeaderNames } from '../utils/Constants.js';
import { ResponseHandler } from '../response/ResponseHandler.js';
import { StringUtils } from '../utils/StringUtils.js';
import { ClientAuthError } from '../error/ClientAuthError.js';
import { UrlString } from '../url/UrlString.js';
import { PopTokenGenerator } from '../crypto/PopTokenGenerator.js';
import { TimeUtils } from '../utils/TimeUtils.js';
import { buildClientInfo, buildClientInfoFromHomeAccountId } from '../account/ClientInfo.js';
import { CcsCredentialType } from '../account/CcsCredential.js';
import { ClientConfigurationError } from '../error/ClientConfigurationError.js';
import { RequestValidator } from '../request/RequestValidator.js';
/*
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License.
*/
/**
* Oauth2.0 Authorization Code client
*/
var AuthorizationCodeClient = /** @class */ (function (_super) {
__extends(AuthorizationCodeClient, _super);
function AuthorizationCodeClient(configuration) {
var _this = _super.call(this, configuration) || this;
// Flag to indicate if client is for hybrid spa auth code redemption
_this.includeRedirectUri = true;
return _this;
}
/**
* Creates the URL of the authorization request letting the user input credentials and consent to the
* application. The URL target the /authorize endpoint of the authority configured in the
* application object.
*
* Once the user inputs their credentials and consents, the authority will send a response to the redirect URI
* sent in the request and should contain an authorization code, which can then be used to acquire tokens via
* acquireToken(AuthorizationCodeRequest)
* @param request
*/
AuthorizationCodeClient.prototype.getAuthCodeUrl = function (request) {
return __awaiter(this, void 0, void 0, function () {
var queryString;
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, this.createAuthCodeUrlQueryString(request)];
case 1:
queryString = _a.sent();
return [2 /*return*/, UrlString.appendQueryString(this.authority.authorizationEndpoint, queryString)];
}
});
});
};
/**
* API to acquire a token in exchange of 'authorization_code` acquired by the user in the first leg of the
* authorization_code_grant
* @param request
*/
AuthorizationCodeClient.prototype.acquireToken = function (request, authCodePayload) {
var _a;
return __awaiter(this, void 0, void 0, function () {
var reqTimestamp, response, requestId, responseHandler;
return __generator(this, function (_b) {
switch (_b.label) {
case 0:
this.logger.info("in acquireToken call");
if (!request || StringUtils.isEmpty(request.code)) {
throw ClientAuthError.createTokenRequestCannotBeMadeError();
}
reqTimestamp = TimeUtils.nowSeconds();
return [4 /*yield*/, this.executeTokenRequest(this.authority, request)];
case 1:
response = _b.sent();
requestId = (_a = response.headers) === null || _a === void 0 ? void 0 : _a[HeaderNames.X_MS_REQUEST_ID];
responseHandler = new ResponseHandler(this.config.authOptions.clientId, this.cacheManager, this.cryptoUtils, this.logger, this.config.serializableCache, this.config.persistencePlugin);
// Validate response. This function throws a server error if an error is returned by the server.
responseHandler.validateTokenResponse(response.body);
return [4 /*yield*/, responseHandler.handleServerTokenResponse(response.body, this.authority, reqTimestamp, request, authCodePayload, undefined, undefined, undefined, requestId)];
case 2: return [2 /*return*/, _b.sent()];
}
});
});
};
/**
* Handles the hash fragment response from public client code request. Returns a code response used by
* the client to exchange for a token in acquireToken.
* @param hashFragment
*/
AuthorizationCodeClient.prototype.handleFragmentResponse = function (hashFragment, cachedState) {
// Handle responses.
var responseHandler = new ResponseHandler(this.config.authOptions.clientId, this.cacheManager, this.cryptoUtils, this.logger, null, null);
// Deserialize hash fragment response parameters.
var hashUrlString = new UrlString(hashFragment);
// Deserialize hash fragment response parameters.
var serverParams = UrlString.getDeserializedHash(hashUrlString.getHash());
// Get code response
responseHandler.validateServerAuthorizationCodeResponse(serverParams, cachedState, this.cryptoUtils);
// throw when there is no auth code in the response
if (!serverParams.code) {
throw ClientAuthError.createNoAuthCodeInServerResponseError();
}
return __assign(__assign({}, serverParams), {
// Code param is optional in ServerAuthorizationCodeResponse but required in AuthorizationCodePaylod
code: serverParams.code });
};
/**
* Used to log out the current user, and redirect the user to the postLogoutRedirectUri.
* Default behaviour is to redirect the user to `window.location.href`.
* @param authorityUri
*/
AuthorizationCodeClient.prototype.getLogoutUri = function (logoutRequest) {
// Throw error if logoutRequest is null/undefined
if (!logoutRequest) {
throw ClientConfigurationError.createEmptyLogoutRequestError();
}
var queryString = this.createLogoutUrlQueryString(logoutRequest);
// Construct logout URI
return UrlString.appendQueryString(this.authority.endSessionEndpoint, queryString);
};
/**
* Executes POST request to token endpoint
* @param authority
* @param request
*/
AuthorizationCodeClient.prototype.executeTokenRequest = function (authority, request) {
return __awaiter(this, void 0, void 0, function () {
var thumbprint, requestBody, queryParameters, ccsCredential, clientInfo, headers, endpoint;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
thumbprint = {
clientId: this.config.authOptions.clientId,
authority: authority.canonicalAuthority,
scopes: request.scopes,
claims: request.claims,
authenticationScheme: request.authenticationScheme,
resourceRequestMethod: request.resourceRequestMethod,
resourceRequestUri: request.resourceRequestUri,
shrClaims: request.shrClaims,
sshKid: request.sshKid
};
return [4 /*yield*/, this.createTokenRequestBody(request)];
case 1:
requestBody = _a.sent();
queryParameters = this.createTokenQueryParameters(request);
ccsCredential = undefined;
if (request.clientInfo) {
try {
clientInfo = buildClientInfo(request.clientInfo, this.cryptoUtils);
ccsCredential = {
credential: "" + clientInfo.uid + Separators.CLIENT_INFO_SEPARATOR + clientInfo.utid,
type: CcsCredentialType.HOME_ACCOUNT_ID
};
}
catch (e) {
this.logger.verbose("Could not parse client info for CCS Header: " + e);
}
}
headers = this.createTokenRequestHeaders(ccsCredential || request.ccsCredential);
endpoint = StringUtils.isEmpty(queryParameters) ? authority.tokenEndpoint : authority.tokenEndpoint + "?" + queryParameters;
return [2 /*return*/, this.executePostToTokenEndpoint(endpoint, requestBody, headers, thumbprint)];
}
});
});
};
/**
* Creates query string for the /token request
* @param request
*/
AuthorizationCodeClient.prototype.createTokenQueryParameters = function (request) {
var parameterBuilder = new RequestParameterBuilder();
if (request.tokenQueryParameters) {
parameterBuilder.addExtraQueryParameters(request.tokenQueryParameters);
}
return parameterBuilder.createQueryString();
};
/**
* Generates a map for all the params to be sent to the service
* @param request
*/
AuthorizationCodeClient.prototype.createTokenRequestBody = function (request) {
return __awaiter(this, void 0, void 0, function () {
var parameterBuilder, clientAssertion, popTokenGenerator, reqCnfData, correlationId, ccsCred, clientInfo, clientInfo;
var _a;
return __generator(this, function (_b) {
switch (_b.label) {
case 0:
parameterBuilder = new RequestParameterBuilder();
parameterBuilder.addClientId(this.config.authOptions.clientId);
/*
* For hybrid spa flow, there will be a code but no verifier
* In this scenario, don't include redirect uri as auth code will not be bound to redirect URI
*/
if (!this.includeRedirectUri) {
// Just validate
RequestValidator.validateRedirectUri(request.redirectUri);
}
else {
// Validate and include redirect uri
parameterBuilder.addRedirectUri(request.redirectUri);
}
// Add scope array, parameter builder will add default scopes and dedupe
parameterBuilder.addScopes(request.scopes);
// add code: user set, not validated
parameterBuilder.addAuthorizationCode(request.code);
// Add library metadata
parameterBuilder.addLibraryInfo(this.config.libraryInfo);
parameterBuilder.addApplicationTelemetry(this.config.telemetry.application);
parameterBuilder.addThrottling();
if (this.serverTelemetryManager) {
parameterBuilder.addServerTelemetry(this.serverTelemetryManager);
}
// add code_verifier if passed
if (request.codeVerifier) {
parameterBuilder.addCodeVerifier(request.codeVerifier);
}
if (this.config.clientCredentials.clientSecret) {
parameterBuilder.addClientSecret(this.config.clientCredentials.clientSecret);
}
if (this.config.clientCredentials.clientAssertion) {
clientAssertion = this.config.clientCredentials.clientAssertion;
parameterBuilder.addClientAssertion(clientAssertion.assertion);
parameterBuilder.addClientAssertionType(clientAssertion.assertionType);
}
parameterBuilder.addGrantType(GrantType.AUTHORIZATION_CODE_GRANT);
parameterBuilder.addClientInfo();
if (!(request.authenticationScheme === AuthenticationScheme.POP)) return [3 /*break*/, 2];
popTokenGenerator = new PopTokenGenerator(this.cryptoUtils);
return [4 /*yield*/, popTokenGenerator.generateCnf(request)];
case 1:
reqCnfData = _b.sent();
// SPA PoP requires full Base64Url encoded req_cnf string (unhashed)
parameterBuilder.addPopToken(reqCnfData.reqCnfString);
return [3 /*break*/, 3];
case 2:
if (request.authenticationScheme === AuthenticationScheme.SSH) {
if (request.sshJwk) {
parameterBuilder.addSshJwk(request.sshJwk);
}
else {
throw ClientConfigurationError.createMissingSshJwkError();
}
}
_b.label = 3;
case 3:
correlationId = request.correlationId || this.config.cryptoInterface.createNewGuid();
parameterBuilder.addCorrelationId(correlationId);
if (!StringUtils.isEmptyObj(request.claims) || this.config.authOptions.clientCapabilities && this.config.authOptions.clientCapabilities.length > 0) {
parameterBuilder.addClaims(request.claims, this.config.authOptions.clientCapabilities);
}
ccsCred = undefined;
if (request.clientInfo) {
try {
clientInfo = buildClientInfo(request.clientInfo, this.cryptoUtils);
ccsCred = {
credential: "" + clientInfo.uid + Separators.CLIENT_INFO_SEPARATOR + clientInfo.utid,
type: CcsCredentialType.HOME_ACCOUNT_ID
};
}
catch (e) {
this.logger.verbose("Could not parse client info for CCS Header: " + e);
}
}
else {
ccsCred = request.ccsCredential;
}
// Adds these as parameters in the request instead of headers to prevent CORS preflight request
if (this.config.systemOptions.preventCorsPreflight && ccsCred) {
switch (ccsCred.type) {
case CcsCredentialType.HOME_ACCOUNT_ID:
try {
clientInfo = buildClientInfoFromHomeAccountId(ccsCred.credential);
parameterBuilder.addCcsOid(clientInfo);
}
catch (e) {
this.logger.verbose("Could not parse home account ID for CCS Header: " + e);
}
break;
case CcsCredentialType.UPN:
parameterBuilder.addCcsUpn(ccsCred.credential);
break;
}
}
if (request.tokenBodyParameters) {
parameterBuilder.addExtraQueryParameters(request.tokenBodyParameters);
}
// Add hybrid spa parameters if not already provided
if (request.enableSpaAuthorizationCode && (!request.tokenBodyParameters || !request.tokenBodyParameters[AADServerParamKeys.RETURN_SPA_CODE])) {
parameterBuilder.addExtraQueryParameters((_a = {},
_a[AADServerParamKeys.RETURN_SPA_CODE] = "1",
_a));
}
return [2 /*return*/, parameterBuilder.createQueryString()];
}
});
});
};
/**
* This API validates the `AuthorizationCodeUrlRequest` and creates a URL
* @param request
*/
AuthorizationCodeClient.prototype.createAuthCodeUrlQueryString = function (request) {
return __awaiter(this, void 0, void 0, function () {
var parameterBuilder, requestScopes, correlationId, accountSid, accountLoginHintClaim, clientInfo, clientInfo, clientInfo, popTokenGenerator, reqCnfData;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
parameterBuilder = new RequestParameterBuilder();
parameterBuilder.addClientId(this.config.authOptions.clientId);
requestScopes = __spreadArrays(request.scopes || [], request.extraScopesToConsent || []);
parameterBuilder.addScopes(requestScopes);
// validate the redirectUri (to be a non null value)
parameterBuilder.addRedirectUri(request.redirectUri);
correlationId = request.correlationId || this.config.cryptoInterface.createNewGuid();
parameterBuilder.addCorrelationId(correlationId);
// add response_mode. If not passed in it defaults to query.
parameterBuilder.addResponseMode(request.responseMode);
// add response_type = code
parameterBuilder.addResponseTypeCode();
// add library info parameters
parameterBuilder.addLibraryInfo(this.config.libraryInfo);
parameterBuilder.addApplicationTelemetry(this.config.telemetry.application);
// add client_info=1
parameterBuilder.addClientInfo();
if (request.codeChallenge && request.codeChallengeMethod) {
parameterBuilder.addCodeChallengeParams(request.codeChallenge, request.codeChallengeMethod);
}
if (request.prompt) {
parameterBuilder.addPrompt(request.prompt);
}
if (request.domainHint) {
parameterBuilder.addDomainHint(request.domainHint);
}
// Add sid or loginHint with preference for login_hint claim (in request) -> sid -> loginHint (upn/email) -> username of AccountInfo object
if (request.prompt !== PromptValue.SELECT_ACCOUNT) {
// AAD will throw if prompt=select_account is passed with an account hint
if (request.sid && request.prompt === PromptValue.NONE) {
// SessionID is only used in silent calls
this.logger.verbose("createAuthCodeUrlQueryString: Prompt is none, adding sid from request");
parameterBuilder.addSid(request.sid);
}
else if (request.account) {
accountSid = this.extractAccountSid(request.account);
accountLoginHintClaim = this.extractLoginHint(request.account);
// If login_hint claim is present, use it over sid/username
if (accountLoginHintClaim) {
this.logger.verbose("createAuthCodeUrlQueryString: login_hint claim present on account");
parameterBuilder.addLoginHint(accountLoginHintClaim);
try {
clientInfo = buildClientInfoFromHomeAccountId(request.account.homeAccountId);
parameterBuilder.addCcsOid(clientInfo);
}
catch (e) {
this.logger.verbose("createAuthCodeUrlQueryString: Could not parse home account ID for CCS Header");
}
}
else if (accountSid && request.prompt === PromptValue.NONE) {
/*
* If account and loginHint are provided, we will check account first for sid before adding loginHint
* SessionId is only used in silent calls
*/
this.logger.verbose("createAuthCodeUrlQueryString: Prompt is none, adding sid from account");
parameterBuilder.addSid(accountSid);
try {
clientInfo = buildClientInfoFromHomeAccountId(request.account.homeAccountId);
parameterBuilder.addCcsOid(clientInfo);
}
catch (e) {
this.logger.verbose("createAuthCodeUrlQueryString: Could not parse home account ID for CCS Header");
}
}
else if (request.loginHint) {
this.logger.verbose("createAuthCodeUrlQueryString: Adding login_hint from request");
parameterBuilder.addLoginHint(request.loginHint);
parameterBuilder.addCcsUpn(request.loginHint);
}
else if (request.account.username) {
// Fallback to account username if provided
this.logger.verbose("createAuthCodeUrlQueryString: Adding login_hint from account");
parameterBuilder.addLoginHint(request.account.username);
try {
clientInfo = buildClientInfoFromHomeAccountId(request.account.homeAccountId);
parameterBuilder.addCcsOid(clientInfo);
}
catch (e) {
this.logger.verbose("createAuthCodeUrlQueryString: Could not parse home account ID for CCS Header");
}
}
}
else if (request.loginHint) {
this.logger.verbose("createAuthCodeUrlQueryString: No account, adding login_hint from request");
parameterBuilder.addLoginHint(request.loginHint);
parameterBuilder.addCcsUpn(request.loginHint);
}
}
else {
this.logger.verbose("createAuthCodeUrlQueryString: Prompt is select_account, ignoring account hints");
}
if (request.nonce) {
parameterBuilder.addNonce(request.nonce);
}
if (request.state) {
parameterBuilder.addState(request.state);
}
if (!StringUtils.isEmpty(request.claims) || this.config.authOptions.clientCapabilities && this.config.authOptions.clientCapabilities.length > 0) {
parameterBuilder.addClaims(request.claims, this.config.authOptions.clientCapabilities);
}
if (request.extraQueryParameters) {
parameterBuilder.addExtraQueryParameters(request.extraQueryParameters);
}
if (!request.nativeBroker) return [3 /*break*/, 2];
// signal ests that this is a WAM call
parameterBuilder.addNativeBroker();
if (!(request.authenticationScheme === AuthenticationScheme.POP)) return [3 /*break*/, 2];
popTokenGenerator = new PopTokenGenerator(this.cryptoUtils);
return [4 /*yield*/, popTokenGenerator.generateCnf(request)];
case 1:
reqCnfData = _a.sent();
parameterBuilder.addPopToken(reqCnfData.reqCnfHash);
_a.label = 2;
case 2: return [2 /*return*/, parameterBuilder.createQueryString()];
}
});
});
};
/**
* This API validates the `EndSessionRequest` and creates a URL
* @param request
*/
AuthorizationCodeClient.prototype.createLogoutUrlQueryString = function (request) {
var parameterBuilder = new RequestParameterBuilder();
if (request.postLogoutRedirectUri) {
parameterBuilder.addPostLogoutRedirectUri(request.postLogoutRedirectUri);
}
if (request.correlationId) {
parameterBuilder.addCorrelationId(request.correlationId);
}
if (request.idTokenHint) {
parameterBuilder.addIdTokenHint(request.idTokenHint);
}
if (request.state) {
parameterBuilder.addState(request.state);
}
if (request.logoutHint) {
parameterBuilder.addLogoutHint(request.logoutHint);
}
if (request.extraQueryParameters) {
parameterBuilder.addExtraQueryParameters(request.extraQueryParameters);
}
return parameterBuilder.createQueryString();
};
/**
* Helper to get sid from account. Returns null if idTokenClaims are not present or sid is not present.
* @param account
*/
AuthorizationCodeClient.prototype.extractAccountSid = function (account) {
var _a;
return ((_a = account.idTokenClaims) === null || _a === void 0 ? void 0 : _a.sid) || null;
};
AuthorizationCodeClient.prototype.extractLoginHint = function (account) {
var _a;
return ((_a = account.idTokenClaims) === null || _a === void 0 ? void 0 : _a.login_hint) || null;
};
return AuthorizationCodeClient;
}(BaseClient));
export { AuthorizationCodeClient };
//# sourceMappingURL=AuthorizationCodeClient.js.map
{"version":3,"file":"AuthorizationCodeClient.js","sources":["../../src/client/AuthorizationCodeClient.ts"],"sourcesContent":["/*\n * Copyright (c) Microsoft Corporation. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { BaseClient } from \"./BaseClient\";\nimport { CommonAuthorizationUrlRequest } from \"../request/CommonAuthorizationUrlRequest\";\nimport { CommonAuthorizationCodeRequest } from \"../request/CommonAuthorizationCodeRequest\";\nimport { Authority } from \"../authority/Authority\";\nimport { RequestParameterBuilder } from \"../request/RequestParameterBuilder\";\nimport { GrantType, AuthenticationScheme, PromptValue, Separators, AADServerParamKeys, HeaderNames } from \"../utils/Constants\";\nimport { ClientConfiguration } from \"../config/ClientConfiguration\";\nimport { ServerAuthorizationTokenResponse } from \"../response/ServerAuthorizationTokenResponse\";\nimport { NetworkResponse } from \"../network/NetworkManager\";\nimport { ResponseHandler } from \"../response/ResponseHandler\";\nimport { AuthenticationResult } from \"../response/AuthenticationResult\";\nimport { StringUtils } from \"../utils/StringUtils\";\nimport { ClientAuthError } from \"../error/ClientAuthError\";\nimport { UrlString } from \"../url/UrlString\";\nimport { ServerAuthorizationCodeResponse } from \"../response/ServerAuthorizationCodeResponse\";\nimport { CommonEndSessionRequest } from \"../request/CommonEndSessionRequest\";\nimport { PopTokenGenerator } from \"../crypto/PopTokenGenerator\";\nimport { RequestThumbprint } from \"../network/RequestThumbprint\";\nimport { AuthorizationCodePayload } from \"../response/AuthorizationCodePayload\";\nimport { TimeUtils } from \"../utils/TimeUtils\";\nimport { AccountInfo } from \"../account/AccountInfo\";\nimport { buildClientInfoFromHomeAccountId, buildClientInfo } from \"../account/ClientInfo\";\nimport { CcsCredentialType, CcsCredential } from \"../account/CcsCredential\";\nimport { ClientConfigurationError } from \"../error/ClientConfigurationError\";\nimport { RequestValidator } from \"../request/RequestValidator\";\n\n/**\n * Oauth2.0 Authorization Code client\n */\nexport class AuthorizationCodeClient extends BaseClient {\n // Flag to indicate if client is for hybrid spa auth code redemption\n protected includeRedirectUri: boolean = true;\n\n constructor(configuration: ClientConfiguration) {\n super(configuration);\n }\n\n /**\n * Creates the URL of the authorization request letting the user input credentials and consent to the\n * application. The URL target the /authorize endpoint of the authority configured in the\n * application object.\n *\n * Once the user inputs their credentials and consents, the authority will send a response to the redirect URI\n * sent in the request and should contain an authorization code, which can then be used to acquire tokens via\n * acquireToken(AuthorizationCodeRequest)\n * @param request\n */\n async getAuthCodeUrl(request: CommonAuthorizationUrlRequest): Promise<string> {\n const queryString = await this.createAuthCodeUrlQueryString(request);\n\n return UrlString.appendQueryString(this.authority.authorizationEndpoint, queryString);\n }\n\n /**\n * API to acquire a token in exchange of 'authorization_code` acquired by the user in the first leg of the\n * authorization_code_grant\n * @param request\n */\n async acquireToken(request: CommonAuthorizationCodeRequest, authCodePayload?: AuthorizationCodePayload): Promise<AuthenticationResult> {\n this.logger.info(\"in acquireToken call\");\n if (!request || StringUtils.isEmpty(request.code)) {\n throw ClientAuthError.createTokenRequestCannotBeMadeError();\n }\n\n const reqTimestamp = TimeUtils.nowSeconds();\n const response = await this.executeTokenRequest(this.authority, request);\n\n // Retrieve requestId from response headers\n const requestId = response.headers?.[HeaderNames.X_MS_REQUEST_ID];\n\n const responseHandler = new ResponseHandler(\n this.config.authOptions.clientId,\n this.cacheManager,\n this.cryptoUtils,\n this.logger,\n this.config.serializableCache,\n this.config.persistencePlugin\n );\n\n // Validate response. This function throws a server error if an error is returned by the server.\n responseHandler.validateTokenResponse(response.body);\n return await responseHandler.handleServerTokenResponse(\n response.body, \n this.authority, \n reqTimestamp, \n request, \n authCodePayload,\n undefined,\n undefined,\n undefined,\n requestId\n );\n }\n\n /**\n * Handles the hash fragment response from public client code request. Returns a code response used by\n * the client to exchange for a token in acquireToken.\n * @param hashFragment\n */\n handleFragmentResponse(hashFragment: string, cachedState: string): AuthorizationCodePayload {\n // Handle responses.\n const responseHandler = new ResponseHandler(this.config.authOptions.clientId, this.cacheManager, this.cryptoUtils, this.logger, null, null);\n\n // Deserialize hash fragment response parameters.\n const hashUrlString = new UrlString(hashFragment);\n // Deserialize hash fragment response parameters.\n const serverParams: ServerAuthorizationCodeResponse = UrlString.getDeserializedHash(hashUrlString.getHash());\n\n // Get code response\n responseHandler.validateServerAuthorizationCodeResponse(serverParams, cachedState, this.cryptoUtils);\n\n // throw when there is no auth code in the response\n if (!serverParams.code) {\n throw ClientAuthError.createNoAuthCodeInServerResponseError();\n }\n return {\n ...serverParams,\n // Code param is optional in ServerAuthorizationCodeResponse but required in AuthorizationCodePaylod\n code: serverParams.code\n };\n }\n\n /**\n * Used to log out the current user, and redirect the user to the postLogoutRedirectUri.\n * Default behaviour is to redirect the user to `window.location.href`.\n * @param authorityUri\n */\n getLogoutUri(logoutRequest: CommonEndSessionRequest): string {\n // Throw error if logoutRequest is null/undefined\n if (!logoutRequest) {\n throw ClientConfigurationError.createEmptyLogoutRequestError();\n }\n const queryString = this.createLogoutUrlQueryString(logoutRequest);\n\n // Construct logout URI\n return UrlString.appendQueryString(this.authority.endSessionEndpoint, queryString);\n }\n\n /**\n * Executes POST request to token endpoint\n * @param authority\n * @param request\n */\n private async executeTokenRequest(authority: Authority, request: CommonAuthorizationCodeRequest): Promise<NetworkResponse<ServerAuthorizationTokenResponse>> {\n const thumbprint: RequestThumbprint = {\n clientId: this.config.authOptions.clientId,\n authority: authority.canonicalAuthority,\n scopes: request.scopes,\n claims: request.claims,\n authenticationScheme: request.authenticationScheme,\n resourceRequestMethod: request.resourceRequestMethod,\n resourceRequestUri: request.resourceRequestUri,\n shrClaims: request.shrClaims,\n sshKid: request.sshKid\n };\n\n const requestBody = await this.createTokenRequestBody(request);\n const queryParameters = this.createTokenQueryParameters(request);\n let ccsCredential: CcsCredential | undefined = undefined;\n if (request.clientInfo) {\n try {\n const clientInfo = buildClientInfo(request.clientInfo, this.cryptoUtils);\n ccsCredential = {\n credential: `${clientInfo.uid}${Separators.CLIENT_INFO_SEPARATOR}${clientInfo.utid}`,\n type: CcsCredentialType.HOME_ACCOUNT_ID\n };\n } catch (e) {\n this.logger.verbose(\"Could not parse client info for CCS Header: \" + e);\n }\n }\n const headers: Record<string, string> = this.createTokenRequestHeaders(ccsCredential || request.ccsCredential);\n const endpoint = StringUtils.isEmpty(queryParameters) ? authority.tokenEndpoint : `${authority.tokenEndpoint}?${queryParameters}`;\n\n return this.executePostToTokenEndpoint(endpoint, requestBody, headers, thumbprint);\n }\n\n /**\n * Creates query string for the /token request\n * @param request\n */\n private createTokenQueryParameters(request: CommonAuthorizationCodeRequest): string {\n const parameterBuilder = new RequestParameterBuilder();\n\n if (request.tokenQueryParameters) {\n parameterBuilder.addExtraQueryParameters(request.tokenQueryParameters);\n }\n\n return parameterBuilder.createQueryString();\n }\n\n /**\n * Generates a map for all the params to be sent to the service\n * @param request\n */\n private async createTokenRequestBody(request: CommonAuthorizationCodeRequest): Promise<string> {\n const parameterBuilder = new RequestParameterBuilder();\n\n parameterBuilder.addClientId(this.config.authOptions.clientId);\n\n /*\n * For hybrid spa flow, there will be a code but no verifier\n * In this scenario, don't include redirect uri as auth code will not be bound to redirect URI\n */\n if (!this.includeRedirectUri) {\n // Just validate\n RequestValidator.validateRedirectUri(request.redirectUri);\n } else {\n // Validate and include redirect uri\n parameterBuilder.addRedirectUri(request.redirectUri);\n }\n\n // Add scope array, parameter builder will add default scopes and dedupe\n parameterBuilder.addScopes(request.scopes);\n\n // add code: user set, not validated\n parameterBuilder.addAuthorizationCode(request.code);\n\n // Add library metadata\n parameterBuilder.addLibraryInfo(this.config.libraryInfo);\n parameterBuilder.addApplicationTelemetry(this.config.telemetry.application);\n parameterBuilder.addThrottling();\n\n if (this.serverTelemetryManager) {\n parameterBuilder.addServerTelemetry(this.serverTelemetryManager);\n }\n\n // add code_verifier if passed\n if (request.codeVerifier) {\n parameterBuilder.addCodeVerifier(request.codeVerifier);\n }\n\n if (this.config.clientCredentials.clientSecret) {\n parameterBuilder.addClientSecret(this.config.clientCredentials.clientSecret);\n }\n\n if (this.config.clientCredentials.clientAssertion) {\n const clientAssertion = this.config.clientCredentials.clientAssertion;\n parameterBuilder.addClientAssertion(clientAssertion.assertion);\n parameterBuilder.addClientAssertionType(clientAssertion.assertionType);\n }\n\n parameterBuilder.addGrantType(GrantType.AUTHORIZATION_CODE_GRANT);\n parameterBuilder.addClientInfo();\n\n if (request.authenticationScheme === AuthenticationScheme.POP) {\n const popTokenGenerator = new PopTokenGenerator(this.cryptoUtils);\n const reqCnfData = await popTokenGenerator.generateCnf(request);\n // SPA PoP requires full Base64Url encoded req_cnf string (unhashed)\n parameterBuilder.addPopToken(reqCnfData.reqCnfString);\n } else if (request.authenticationScheme === AuthenticationScheme.SSH) {\n if(request.sshJwk) {\n parameterBuilder.addSshJwk(request.sshJwk);\n } else {\n throw ClientConfigurationError.createMissingSshJwkError();\n }\n }\n\n const correlationId = request.correlationId || this.config.cryptoInterface.createNewGuid();\n parameterBuilder.addCorrelationId(correlationId);\n\n if (!StringUtils.isEmptyObj(request.claims) || this.config.authOptions.clientCapabilities && this.config.authOptions.clientCapabilities.length > 0) {\n parameterBuilder.addClaims(request.claims, this.config.authOptions.clientCapabilities);\n }\n\n let ccsCred: CcsCredential | undefined = undefined;\n if (request.clientInfo) {\n try {\n const clientInfo = buildClientInfo(request.clientInfo, this.cryptoUtils);\n ccsCred = {\n credential: `${clientInfo.uid}${Separators.CLIENT_INFO_SEPARATOR}${clientInfo.utid}`,\n type: CcsCredentialType.HOME_ACCOUNT_ID\n };\n } catch (e) {\n this.logger.verbose(\"Could not parse client info for CCS Header: \" + e);\n }\n } else {\n ccsCred = request.ccsCredential;\n }\n\n // Adds these as parameters in the request instead of headers to prevent CORS preflight request\n if (this.config.systemOptions.preventCorsPreflight && ccsCred) {\n switch (ccsCred.type) {\n case CcsCredentialType.HOME_ACCOUNT_ID:\n try {\n const clientInfo = buildClientInfoFromHomeAccountId(ccsCred.credential);\n parameterBuilder.addCcsOid(clientInfo);\n } catch (e) {\n this.logger.verbose(\"Could not parse home account ID for CCS Header: \" + e);\n }\n break;\n case CcsCredentialType.UPN:\n parameterBuilder.addCcsUpn(ccsCred.credential);\n break;\n }\n }\n\n if (request.tokenBodyParameters) {\n parameterBuilder.addExtraQueryParameters(request.tokenBodyParameters);\n }\n\n // Add hybrid spa parameters if not already provided\n if (request.enableSpaAuthorizationCode && (!request.tokenBodyParameters || !request.tokenBodyParameters[AADServerParamKeys.RETURN_SPA_CODE])) {\n parameterBuilder.addExtraQueryParameters({\n [AADServerParamKeys.RETURN_SPA_CODE]: \"1\"\n });\n }\n\n return parameterBuilder.createQueryString();\n }\n\n /**\n * This API validates the `AuthorizationCodeUrlRequest` and creates a URL\n * @param request\n */\n private async createAuthCodeUrlQueryString(request: CommonAuthorizationUrlRequest): Promise<string> {\n const parameterBuilder = new RequestParameterBuilder();\n\n parameterBuilder.addClientId(this.config.authOptions.clientId);\n\n const requestScopes = [...request.scopes || [], ...request.extraScopesToConsent || []];\n parameterBuilder.addScopes(requestScopes);\n\n // validate the redirectUri (to be a non null value)\n parameterBuilder.addRedirectUri(request.redirectUri);\n\n // generate the correlationId if not set by the user and add\n const correlationId = request.correlationId || this.config.cryptoInterface.createNewGuid();\n parameterBuilder.addCorrelationId(correlationId);\n\n // add response_mode. If not passed in it defaults to query.\n parameterBuilder.addResponseMode(request.responseMode);\n\n // add response_type = code\n parameterBuilder.addResponseTypeCode();\n\n // add library info parameters\n parameterBuilder.addLibraryInfo(this.config.libraryInfo);\n parameterBuilder.addApplicationTelemetry(this.config.telemetry.application);\n\n // add client_info=1\n parameterBuilder.addClientInfo();\n\n if (request.codeChallenge && request.codeChallengeMethod) {\n parameterBuilder.addCodeChallengeParams(request.codeChallenge, request.codeChallengeMethod);\n }\n\n if (request.prompt) {\n parameterBuilder.addPrompt(request.prompt);\n }\n\n if (request.domainHint) {\n parameterBuilder.addDomainHint(request.domainHint);\n }\n\n // Add sid or loginHint with preference for login_hint claim (in request) -> sid -> loginHint (upn/email) -> username of AccountInfo object\n if (request.prompt !== PromptValue.SELECT_ACCOUNT) {\n // AAD will throw if prompt=select_account is passed with an account hint\n if (request.sid && request.prompt === PromptValue.NONE) {\n // SessionID is only used in silent calls\n this.logger.verbose(\"createAuthCodeUrlQueryString: Prompt is none, adding sid from request\");\n parameterBuilder.addSid(request.sid);\n } else if (request.account) {\n const accountSid = this.extractAccountSid(request.account);\n const accountLoginHintClaim = this.extractLoginHint(request.account);\n // If login_hint claim is present, use it over sid/username\n if (accountLoginHintClaim) {\n this.logger.verbose(\"createAuthCodeUrlQueryString: login_hint claim present on account\");\n parameterBuilder.addLoginHint(accountLoginHintClaim);\n try {\n const clientInfo = buildClientInfoFromHomeAccountId(request.account.homeAccountId);\n parameterBuilder.addCcsOid(clientInfo);\n } catch (e) {\n this.logger.verbose(\"createAuthCodeUrlQueryString: Could not parse home account ID for CCS Header\");\n }\n } else if (accountSid && request.prompt === PromptValue.NONE) {\n /*\n * If account and loginHint are provided, we will check account first for sid before adding loginHint\n * SessionId is only used in silent calls\n */\n this.logger.verbose(\"createAuthCodeUrlQueryString: Prompt is none, adding sid from account\");\n parameterBuilder.addSid(accountSid);\n try {\n const clientInfo = buildClientInfoFromHomeAccountId(request.account.homeAccountId);\n parameterBuilder.addCcsOid(clientInfo);\n } catch (e) {\n this.logger.verbose(\"createAuthCodeUrlQueryString: Could not parse home account ID for CCS Header\");\n }\n } else if (request.loginHint) {\n this.logger.verbose(\"createAuthCodeUrlQueryString: Adding login_hint from request\");\n parameterBuilder.addLoginHint(request.loginHint);\n parameterBuilder.addCcsUpn(request.loginHint);\n } else if (request.account.username) {\n // Fallback to account username if provided\n this.logger.verbose(\"createAuthCodeUrlQueryString: Adding login_hint from account\");\n parameterBuilder.addLoginHint(request.account.username);\n try {\n const clientInfo = buildClientInfoFromHomeAccountId(request.account.homeAccountId);\n parameterBuilder.addCcsOid(clientInfo);\n } catch (e) {\n this.logger.verbose(\"createAuthCodeUrlQueryString: Could not parse home account ID for CCS Header\");\n }\n }\n } else if (request.loginHint) {\n this.logger.verbose(\"createAuthCodeUrlQueryString: No account, adding login_hint from request\");\n parameterBuilder.addLoginHint(request.loginHint);\n parameterBuilder.addCcsUpn(request.loginHint);\n }\n } else {\n this.logger.verbose(\"createAuthCodeUrlQueryString: Prompt is select_account, ignoring account hints\");\n }\n\n if (request.nonce) {\n parameterBuilder.addNonce(request.nonce);\n }\n\n if (request.state) {\n parameterBuilder.addState(request.state);\n }\n\n if (!StringUtils.isEmpty(request.claims) || this.config.authOptions.clientCapabilities && this.config.authOptions.clientCapabilities.length > 0) {\n parameterBuilder.addClaims(request.claims, this.config.authOptions.clientCapabilities);\n }\n\n if (request.extraQueryParameters) {\n parameterBuilder.addExtraQueryParameters(request.extraQueryParameters);\n }\n\n if (request.nativeBroker) {\n // signal ests that this is a WAM call\n parameterBuilder.addNativeBroker();\n\n // pass the req_cnf for POP\n if (request.authenticationScheme === AuthenticationScheme.POP) {\n const popTokenGenerator = new PopTokenGenerator(this.cryptoUtils);\n // to reduce the URL length, it is recommended to send the hash of the req_cnf instead of the whole string\n const reqCnfData = await popTokenGenerator.generateCnf(request);\n parameterBuilder.addPopToken(reqCnfData.reqCnfHash);\n }\n }\n\n return parameterBuilder.createQueryString();\n }\n\n /**\n * This API validates the `EndSessionRequest` and creates a URL\n * @param request\n */\n private createLogoutUrlQueryString(request: CommonEndSessionRequest): string {\n const parameterBuilder = new RequestParameterBuilder();\n\n if (request.postLogoutRedirectUri) {\n parameterBuilder.addPostLogoutRedirectUri(request.postLogoutRedirectUri);\n }\n\n if (request.correlationId) {\n parameterBuilder.addCorrelationId(request.correlationId);\n }\n\n if (request.idTokenHint) {\n parameterBuilder.addIdTokenHint(request.idTokenHint);\n }\n\n if(request.state) {\n parameterBuilder.addState(request.state);\n }\n\n if (request.logoutHint) {\n parameterBuilder.addLogoutHint(request.logoutHint);\n }\n\n if (request.extraQueryParameters) {\n parameterBuilder.addExtraQueryParameters(request.extraQueryParameters);\n }\n\n return parameterBuilder.createQueryString();\n }\n\n /**\n * Helper to get sid from account. Returns null if idTokenClaims are not present or sid is not present.\n * @param account\n */\n private extractAccountSid(account: AccountInfo): string | null {\n return account.idTokenClaims?.sid || null;\n }\n\n private extractLoginHint(account: AccountInfo): string | null {\n return account.idTokenClaims?.login_hint || null;\n }\n}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A,CAAA,EAAA,GAAA,OAAO,CAAC,aAAa,0CAAE,GAAG,KAAI,IAAI,CAAC;KAC7C,CAAA;IAEO,uBAAgB,CAAA,SAAA,CAAA,gBAAA,GAAxB,UAAyB,OAAoB,EAAA;;QACzC,OAAO,CAAA,CAAA,EAAA,GAAA,OAAO,CAAC,aAAa,0CAAE,UAAU,KAAI,IAAI,CAAC;KACpD,CAAA;IACL,OAAC,uBAAA,CAAA;AAAD,CA3cA,CAA6C,UAAU,CA2ctD;;;;"}
\ No newline at end of file
import { ClientConfiguration, CommonClientConfiguration } from "../config/ClientConfiguration";
import { INetworkModule } from "../network/INetworkModule";
import { NetworkManager, NetworkResponse } from "../network/NetworkManager";
import { ICrypto } from "../crypto/ICrypto";
import { Authority } from "../authority/Authority";
import { Logger } from "../logger/Logger";
import { ServerAuthorizationTokenResponse } from "../response/ServerAuthorizationTokenResponse";
import { CacheManager } from "../cache/CacheManager";
import { ServerTelemetryManager } from "../telemetry/server/ServerTelemetryManager";
import { RequestThumbprint } from "../network/RequestThumbprint";
import { CcsCredential } from "../account/CcsCredential";
import { IPerformanceClient } from "../telemetry/performance/IPerformanceClient";
/**
* Base application class which will construct requests to send to and handle responses from the Microsoft STS using the authorization code flow.
*/
export declare abstract class BaseClient {
logger: Logger;
protected config: CommonClientConfiguration;
protected cryptoUtils: ICrypto;
protected cacheManager: CacheManager;
protected networkClient: INetworkModule;
protected serverTelemetryManager: ServerTelemetryManager | null;
protected networkManager: NetworkManager;
authority: Authority;
protected performanceClient?: IPerformanceClient;
protected constructor(configuration: ClientConfiguration, performanceClient?: IPerformanceClient);
/**
* Creates default headers for requests to token endpoint
*/
protected createTokenRequestHeaders(ccsCred?: CcsCredential): Record<string, string>;
/**
* Http post to token endpoint
* @param tokenEndpoint
* @param queryString
* @param headers
* @param thumbprint
*/
protected executePostToTokenEndpoint(tokenEndpoint: string, queryString: string, headers: Record<string, string>, thumbprint: RequestThumbprint): Promise<NetworkResponse<ServerAuthorizationTokenResponse>>;
/**
* Updates the authority object of the client. Endpoint discovery must be completed.
* @param updatedAuthority
*/
updateAuthority(updatedAuthority: Authority): void;
}
//# sourceMappingURL=BaseClient.d.ts.map
\ No newline at end of file
{"version":3,"file":"BaseClient.d.ts","sourceRoot":"","sources":["../../src/client/BaseClient.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,mBAAmB,EAA4B,yBAAyB,EAAE,MAAM,+BAA+B,CAAC;AACzH,OAAO,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAC3D,OAAO,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,2BAA2B,CAAC;AAC5E,OAAO,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAC5C,OAAO,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAC;AACnD,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAE1C,OAAO,EAAE,gCAAgC,EAAE,MAAM,8CAA8C,CAAC;AAChG,OAAO,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AACrD,OAAO,EAAE,sBAAsB,EAAE,MAAM,4CAA4C,CAAC;AACpF,OAAO,EAAE,iBAAiB,EAAE,MAAM,8BAA8B,CAAC;AAGjE,OAAO,EAAE,aAAa,EAAqB,MAAM,0BAA0B,CAAC;AAE5E,OAAO,EAAE,kBAAkB,EAAE,MAAM,6CAA6C,CAAC;AAEjF;;GAEG;AACH,8BAAsB,UAAU;IAErB,MAAM,EAAE,MAAM,CAAC;IAGtB,SAAS,CAAC,MAAM,EAAE,yBAAyB,CAAC;IAG5C,SAAS,CAAC,WAAW,EAAE,OAAO,CAAC;IAG/B,SAAS,CAAC,YAAY,EAAE,YAAY,CAAC;IAGrC,SAAS,CAAC,aAAa,EAAE,cAAc,CAAC;IAGxC,SAAS,CAAC,sBAAsB,EAAE,sBAAsB,GAAG,IAAI,CAAC;IAGhE,SAAS,CAAC,cAAc,EAAE,cAAc,CAAC;IAGlC,SAAS,EAAE,SAAS,CAAC;IAG5B,SAAS,CAAC,iBAAiB,CAAC,EAAE,kBAAkB,CAAC;IAEjD,SAAS,aAAa,aAAa,EAAE,mBAAmB,EAAE,iBAAiB,CAAC,EAAE,kBAAkB;IA6BhG;;OAEG;IACH,SAAS,CAAC,yBAAyB,CAAC,OAAO,CAAC,EAAE,aAAa,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC;IAsBpF;;;;;;OAMG;cACa,0BAA0B,CAAC,aAAa,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,EAAE,UAAU,EAAE,iBAAiB,GAAG,OAAO,CAAC,eAAe,CAAC,gCAAgC,CAAC,CAAC;IAelN;;;OAGG;IACH,eAAe,CAAC,gBAAgB,EAAE,SAAS,GAAG,IAAI;CAMrD"}
\ No newline at end of file
/*! @azure/msal-common v9.0.1 2022-12-07 */
'use strict';
import { __awaiter, __generator } from '../_virtual/_tslib.js';
import { buildClientConfiguration } from '../config/ClientConfiguration.js';
import { NetworkManager } from '../network/NetworkManager.js';
import { Logger } from '../logger/Logger.js';
import { HeaderNames, Constants } from '../utils/Constants.js';
import { name, version } from '../packageMetadata.js';
import { ClientAuthError } from '../error/ClientAuthError.js';
import { CcsCredentialType } from '../account/CcsCredential.js';
import { buildClientInfoFromHomeAccountId } from '../account/ClientInfo.js';
/*
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License.
*/
/**
* Base application class which will construct requests to send to and handle responses from the Microsoft STS using the authorization code flow.
*/
var BaseClient = /** @class */ (function () {
function BaseClient(configuration, performanceClient) {
// Set the configuration
this.config = buildClientConfiguration(configuration);
// Initialize the logger
this.logger = new Logger(this.config.loggerOptions, name, version);
// Initialize crypto
this.cryptoUtils = this.config.cryptoInterface;
// Initialize storage interface
this.cacheManager = this.config.storageInterface;
// Set the network interface
this.networkClient = this.config.networkInterface;
// Set the NetworkManager
this.networkManager = new NetworkManager(this.networkClient, this.cacheManager);
// Set TelemetryManager
this.serverTelemetryManager = this.config.serverTelemetryManager;
// set Authority
this.authority = this.config.authOptions.authority;
// set performance telemetry client
this.performanceClient = performanceClient;
}
/**
* Creates default headers for requests to token endpoint
*/
BaseClient.prototype.createTokenRequestHeaders = function (ccsCred) {
var headers = {};
headers[HeaderNames.CONTENT_TYPE] = Constants.URL_FORM_CONTENT_TYPE;
if (!this.config.systemOptions.preventCorsPreflight && ccsCred) {
switch (ccsCred.type) {
case CcsCredentialType.HOME_ACCOUNT_ID:
try {
var clientInfo = buildClientInfoFromHomeAccountId(ccsCred.credential);
headers[HeaderNames.CCS_HEADER] = "Oid:" + clientInfo.uid + "@" + clientInfo.utid;
}
catch (e) {
this.logger.verbose("Could not parse home account ID for CCS Header: " + e);
}
break;
case CcsCredentialType.UPN:
headers[HeaderNames.CCS_HEADER] = "UPN: " + ccsCred.credential;
break;
}
}
return headers;
};
/**
* Http post to token endpoint
* @param tokenEndpoint
* @param queryString
* @param headers
* @param thumbprint
*/
BaseClient.prototype.executePostToTokenEndpoint = function (tokenEndpoint, queryString, headers, thumbprint) {
return __awaiter(this, void 0, void 0, function () {
var response;
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, this.networkManager.sendPostRequest(thumbprint, tokenEndpoint, { body: queryString, headers: headers, proxyUrl: this.config.systemOptions.proxyUrl })];
case 1:
response = _a.sent();
if (this.config.serverTelemetryManager && response.status < 500 && response.status !== 429) {
// Telemetry data successfully logged by server, clear Telemetry cache
this.config.serverTelemetryManager.clearTelemetryCache();
}
return [2 /*return*/, response];
}
});
});
};
/**
* Updates the authority object of the client. Endpoint discovery must be completed.
* @param updatedAuthority
*/
BaseClient.prototype.updateAuthority = function (updatedAuthority) {
if (!updatedAuthority.discoveryComplete()) {
throw ClientAuthError.createEndpointDiscoveryIncompleteError("Updated authority has not completed endpoint discovery.");
}
this.authority = updatedAuthority;
};
return BaseClient;
}());
export { BaseClient };
//# sourceMappingURL=BaseClient.js.map
{"version":3,"file":"BaseClient.js","sources":["../../src/client/BaseClient.ts"],"sourcesContent":["/*\n * Copyright (c) Microsoft Corporation. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { ClientConfiguration, buildClientConfiguration, CommonClientConfiguration } from \"../config/ClientConfiguration\";\nimport { INetworkModule } from \"../network/INetworkModule\";\nimport { NetworkManager, NetworkResponse } from \"../network/NetworkManager\";\nimport { ICrypto } from \"../crypto/ICrypto\";\nimport { Authority } from \"../authority/Authority\";\nimport { Logger } from \"../logger/Logger\";\nimport { Constants, HeaderNames } from \"../utils/Constants\";\nimport { ServerAuthorizationTokenResponse } from \"../response/ServerAuthorizationTokenResponse\";\nimport { CacheManager } from \"../cache/CacheManager\";\nimport { ServerTelemetryManager } from \"../telemetry/server/ServerTelemetryManager\";\nimport { RequestThumbprint } from \"../network/RequestThumbprint\";\nimport { version, name } from \"../packageMetadata\";\nimport { ClientAuthError } from \"../error/ClientAuthError\";\nimport { CcsCredential, CcsCredentialType } from \"../account/CcsCredential\";\nimport { buildClientInfoFromHomeAccountId } from \"../account/ClientInfo\";\nimport { IPerformanceClient } from \"../telemetry/performance/IPerformanceClient\";\n\n/**\n * Base application class which will construct requests to send to and handle responses from the Microsoft STS using the authorization code flow.\n */\nexport abstract class BaseClient {\n // Logger object\n public logger: Logger;\n\n // Application config\n protected config: CommonClientConfiguration;\n\n // Crypto Interface\n protected cryptoUtils: ICrypto;\n\n // Storage Interface\n protected cacheManager: CacheManager;\n\n // Network Interface\n protected networkClient: INetworkModule;\n\n // Server Telemetry Manager\n protected serverTelemetryManager: ServerTelemetryManager | null;\n\n // Network Manager\n protected networkManager: NetworkManager;\n\n // Default authority object\n public authority: Authority;\n\n // Performance telemetry client\n protected performanceClient?: IPerformanceClient;\n\n protected constructor(configuration: ClientConfiguration, performanceClient?: IPerformanceClient) {\n // Set the configuration\n this.config = buildClientConfiguration(configuration);\n\n // Initialize the logger\n this.logger = new Logger(this.config.loggerOptions, name, version);\n\n // Initialize crypto\n this.cryptoUtils = this.config.cryptoInterface;\n\n // Initialize storage interface\n this.cacheManager = this.config.storageInterface;\n\n // Set the network interface\n this.networkClient = this.config.networkInterface;\n\n // Set the NetworkManager\n this.networkManager = new NetworkManager(this.networkClient, this.cacheManager);\n\n // Set TelemetryManager\n this.serverTelemetryManager = this.config.serverTelemetryManager;\n\n // set Authority\n this.authority = this.config.authOptions.authority;\n\n // set performance telemetry client\n this.performanceClient = performanceClient;\n }\n\n /**\n * Creates default headers for requests to token endpoint\n */\n protected createTokenRequestHeaders(ccsCred?: CcsCredential): Record<string, string> { \n const headers: Record<string, string> = {};\n headers[HeaderNames.CONTENT_TYPE] = Constants.URL_FORM_CONTENT_TYPE;\n\n if (!this.config.systemOptions.preventCorsPreflight && ccsCred) {\n switch (ccsCred.type) {\n case CcsCredentialType.HOME_ACCOUNT_ID:\n try {\n const clientInfo = buildClientInfoFromHomeAccountId(ccsCred.credential);\n headers[HeaderNames.CCS_HEADER] = `Oid:${clientInfo.uid}@${clientInfo.utid}`;\n } catch (e) {\n this.logger.verbose(\"Could not parse home account ID for CCS Header: \" + e);\n }\n break;\n case CcsCredentialType.UPN:\n headers[HeaderNames.CCS_HEADER] = `UPN: ${ccsCred.credential}`;\n break;\n }\n } \n return headers;\n }\n\n /**\n * Http post to token endpoint\n * @param tokenEndpoint\n * @param queryString\n * @param headers\n * @param thumbprint\n */\n protected async executePostToTokenEndpoint(tokenEndpoint: string, queryString: string, headers: Record<string, string>, thumbprint: RequestThumbprint): Promise<NetworkResponse<ServerAuthorizationTokenResponse>> {\n const response = await this.networkManager.sendPostRequest<ServerAuthorizationTokenResponse>(\n thumbprint,\n tokenEndpoint,\n { body: queryString, headers: headers, proxyUrl: this.config.systemOptions.proxyUrl }\n );\n\n if (this.config.serverTelemetryManager && response.status < 500 && response.status !== 429) {\n // Telemetry data successfully logged by server, clear Telemetry cache\n this.config.serverTelemetryManager.clearTelemetryCache();\n }\n\n return response;\n }\n\n /**\n * Updates the authority object of the client. Endpoint discovery must be completed.\n * @param updatedAuthority\n */\n updateAuthority(updatedAuthority: Authority): void {\n if (!updatedAuthority.discoveryComplete()) {\n throw ClientAuthError.createEndpointDiscoveryIncompleteError(\"Updated authority has not completed endpoint discovery.\");\n }\n this.authority = updatedAuthority;\n }\n}\n"],"names":[],"mappings":";;;;;;;;;;;;AAAA;;;AAGG;AAmBH;;AAEG;AACH,IAAA,UAAA,kBAAA,YAAA;IA4BI,SAAsB,UAAA,CAAA,aAAkC,EAAE,iBAAsC,EAAA;;AAE5F,QAAA,IAAI,CAAC,MAAM,GAAG,wBAAwB,CAAC,aAAa,CAAC,CAAC;;AAGtD,QAAA,IAAI,CAAC,MAAM,GAAG,IAAI,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,aAAa,EAAE,IAAI,EAAE,OAAO,CAAC,CAAC;;QAGnE,IAAI,CAAC,WAAW,GAAG,IAAI,CAAC,MAAM,CAAC,eAAe,CAAC;;QAG/C,IAAI,CAAC,YAAY,GAAG,IAAI,CAAC,MAAM,CAAC,gBAAgB,CAAC;;QAGjD,IAAI,CAAC,aAAa,GAAG,IAAI,CAAC,MAAM,CAAC,gBAAgB,CAAC;;AAGlD,QAAA,IAAI,CAAC,cAAc,GAAG,IAAI,cAAc,CAAC,IAAI,CAAC,aAAa,EAAE,IAAI,CAAC,YAAY,CAAC,CAAC;;QAGhF,IAAI,CAAC,sBAAsB,GAAG,IAAI,CAAC,MAAM,CAAC,sBAAsB,CAAC;;QAGjE,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC,MAAM,CAAC,WAAW,CAAC,SAAS,CAAC;;AAGnD,QAAA,IAAI,CAAC,iBAAiB,GAAG,iBAAiB,CAAC;KAC9C;AAED;;AAEG;IACO,UAAyB,CAAA,SAAA,CAAA,yBAAA,GAAnC,UAAoC,OAAuB,EAAA;QACvD,IAAM,OAAO,GAA2B,EAAE,CAAC;QAC3C,OAAO,CAAC,WAAW,CAAC,YAAY,CAAC,GAAG,SAAS,CAAC,qBAAqB,CA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AAQ,CAAC,MAAM,KAAK,GAAG,EAAE;;AAExF,4BAAA,IAAI,CAAC,MAAM,CAAC,sBAAsB,CAAC,mBAAmB,EAAE,CAAC;AAC5D,yBAAA;AAED,wBAAA,OAAA,CAAA,CAAA,aAAO,QAAQ,CAAC,CAAA;;;;AACnB,KAAA,CAAA;AAED;;;AAGG;IACH,UAAe,CAAA,SAAA,CAAA,eAAA,GAAf,UAAgB,gBAA2B,EAAA;AACvC,QAAA,IAAI,CAAC,gBAAgB,CAAC,iBAAiB,EAAE,EAAE;AACvC,YAAA,MAAM,eAAe,CAAC,sCAAsC,CAAC,yDAAyD,CAAC,CAAC;AAC3H,SAAA;AACD,QAAA,IAAI,CAAC,SAAS,GAAG,gBAAgB,CAAC;KACrC,CAAA;IACL,OAAC,UAAA,CAAA;AAAD,CAAC,EAAA;;;;"}
\ No newline at end of file
import { ClientConfiguration } from "../config/ClientConfiguration";
import { BaseClient } from "./BaseClient";
import { AuthenticationResult } from "../response/AuthenticationResult";
import { CommonClientCredentialRequest } from "../request/CommonClientCredentialRequest";
import { IAppTokenProvider } from "../config/AppTokenProvider";
/**
* OAuth2.0 client credential grant
*/
export declare class ClientCredentialClient extends BaseClient {
private scopeSet;
private readonly appTokenProvider?;
constructor(configuration: ClientConfiguration, appTokenProvider?: IAppTokenProvider);
/**
* Public API to acquire a token with ClientCredential Flow for Confidential clients
* @param request
*/
acquireToken(request: CommonClientCredentialRequest): Promise<AuthenticationResult | null>;
/**
* looks up cache if the tokens are cached already
*/
private getCachedAuthenticationResult;
/**
* Reads access token from the cache
* TODO: Move this call to cacheManager instead
*/
private readAccessTokenFromCache;
/**
* Makes a network call to request the token from the service
* @param request
* @param authority
*/
private executeTokenRequest;
/**
* generate the request to the server in the acceptable format
* @param request
*/
private createTokenRequestBody;
}
//# sourceMappingURL=ClientCredentialClient.d.ts.map
\ No newline at end of file
{"version":3,"file":"ClientCredentialClient.d.ts","sourceRoot":"","sources":["../../src/client/ClientCredentialClient.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,mBAAmB,EAAE,MAAM,+BAA+B,CAAC;AACpE,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAM1C,OAAO,EAAE,oBAAoB,EAAE,MAAM,kCAAkC,CAAC;AACxE,OAAO,EAAE,6BAA6B,EAAE,MAAM,0CAA0C,CAAC;AAQzF,OAAO,EAAE,iBAAiB,EAAE,MAAM,4BAA4B,CAAC;AAE/D;;GAEG;AACH,qBAAa,sBAAuB,SAAQ,UAAU;IAElD,OAAO,CAAC,QAAQ,CAAW;IAC3B,OAAO,CAAC,QAAQ,CAAC,gBAAgB,CAAC,CAAoB;gBAE1C,aAAa,EAAE,mBAAmB,EAAE,gBAAgB,CAAC,EAAE,iBAAiB;IAKpF;;;OAGG;IACU,YAAY,CAAC,OAAO,EAAE,6BAA6B,GAAG,OAAO,CAAC,oBAAoB,GAAG,IAAI,CAAC;IAgBvG;;OAEG;YACW,6BAA6B;IA6B3C;;;OAGG;IACH,OAAO,CAAC,wBAAwB;IAmBhC;;;;OAIG;YACW,mBAAmB;IAkEjC;;;OAGG;IACH,OAAO,CAAC,sBAAsB;CAuCjC"}
\ No newline at end of file
/*! @azure/msal-common v9.0.1 2022-12-07 */
'use strict';
import { __extends, __awaiter, __generator } from '../_virtual/_tslib.js';
import { BaseClient } from './BaseClient.js';
import { RequestParameterBuilder } from '../request/RequestParameterBuilder.js';
import { ScopeSet } from '../request/ScopeSet.js';
import { Constants, CredentialType, GrantType, CacheOutcome, AuthenticationScheme } from '../utils/Constants.js';
import { ResponseHandler } from '../response/ResponseHandler.js';
import { TimeUtils } from '../utils/TimeUtils.js';
import { StringUtils } from '../utils/StringUtils.js';
import { ClientAuthError } from '../error/ClientAuthError.js';
/*
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License.
*/
/**
* OAuth2.0 client credential grant
*/
var ClientCredentialClient = /** @class */ (function (_super) {
__extends(ClientCredentialClient, _super);
function ClientCredentialClient(configuration, appTokenProvider) {
var _this = _super.call(this, configuration) || this;
_this.appTokenProvider = appTokenProvider;
return _this;
}
/**
* Public API to acquire a token with ClientCredential Flow for Confidential clients
* @param request
*/
ClientCredentialClient.prototype.acquireToken = function (request) {
return __awaiter(this, void 0, void 0, function () {
var cachedAuthenticationResult;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
this.scopeSet = new ScopeSet(request.scopes || []);
if (!request.skipCache) return [3 /*break*/, 2];
return [4 /*yield*/, this.executeTokenRequest(request, this.authority)];
case 1: return [2 /*return*/, _a.sent()];
case 2: return [4 /*yield*/, this.getCachedAuthenticationResult(request)];
case 3:
cachedAuthenticationResult = _a.sent();
if (!cachedAuthenticationResult) return [3 /*break*/, 4];
return [2 /*return*/, cachedAuthenticationResult];
case 4: return [4 /*yield*/, this.executeTokenRequest(request, this.authority)];
case 5: return [2 /*return*/, _a.sent()];
}
});
});
};
/**
* looks up cache if the tokens are cached already
*/
ClientCredentialClient.prototype.getCachedAuthenticationResult = function (request) {
var _a, _b;
return __awaiter(this, void 0, void 0, function () {
var cachedAccessToken;
return __generator(this, function (_c) {
switch (_c.label) {
case 0:
cachedAccessToken = this.readAccessTokenFromCache();
if (!cachedAccessToken) {
(_a = this.serverTelemetryManager) === null || _a === void 0 ? void 0 : _a.setCacheOutcome(CacheOutcome.NO_CACHED_ACCESS_TOKEN);
return [2 /*return*/, null];
}
if (TimeUtils.isTokenExpired(cachedAccessToken.expiresOn, this.config.systemOptions.tokenRenewalOffsetSeconds)) {
(_b = this.serverTelemetryManager) === null || _b === void 0 ? void 0 : _b.setCacheOutcome(CacheOutcome.CACHED_ACCESS_TOKEN_EXPIRED);
return [2 /*return*/, null];
}
return [4 /*yield*/, ResponseHandler.generateAuthenticationResult(this.cryptoUtils, this.authority, {
account: null,
idToken: null,
accessToken: cachedAccessToken,
refreshToken: null,
appMetadata: null
}, true, request)];
case 1: return [2 /*return*/, _c.sent()];
}
});
});
};
/**
* Reads access token from the cache
* TODO: Move this call to cacheManager instead
*/
ClientCredentialClient.prototype.readAccessTokenFromCache = function () {
var accessTokenFilter = {
homeAccountId: Constants.EMPTY_STRING,
environment: this.authority.canonicalAuthorityUrlComponents.HostNameAndPort,
credentialType: CredentialType.ACCESS_TOKEN,
clientId: this.config.authOptions.clientId,
realm: this.authority.tenant,
target: this.scopeSet.printScopesLowerCase()
};
var credentialCache = this.cacheManager.getCredentialsFilteredBy(accessTokenFilter);
var accessTokens = Object.keys(credentialCache.accessTokens).map(function (key) { return credentialCache.accessTokens[key]; });
if (accessTokens.length < 1) {
return null;
}
else if (accessTokens.length > 1) {
throw ClientAuthError.createMultipleMatchingTokensInCacheError();
}
return accessTokens[0];
};
/**
* Makes a network call to request the token from the service
* @param request
* @param authority
*/
ClientCredentialClient.prototype.executeTokenRequest = function (request, authority) {
return __awaiter(this, void 0, void 0, function () {
var serverTokenResponse, reqTimestamp, appTokenPropviderParameters, appTokenProviderResult, requestBody, headers, thumbprint, response, responseHandler, tokenResponse;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
if (!this.appTokenProvider) return [3 /*break*/, 2];
this.logger.info("Using appTokenProvider extensibility.");
appTokenPropviderParameters = {
correlationId: request.correlationId,
tenantId: this.config.authOptions.authority.tenant,
scopes: request.scopes,
claims: request.claims,
};
reqTimestamp = TimeUtils.nowSeconds();
return [4 /*yield*/, this.appTokenProvider(appTokenPropviderParameters)];
case 1:
appTokenProviderResult = _a.sent();
serverTokenResponse = {
access_token: appTokenProviderResult.accessToken,
expires_in: appTokenProviderResult.expiresInSeconds,
refresh_in: appTokenProviderResult.refreshInSeconds,
token_type: AuthenticationScheme.BEARER
};
return [3 /*break*/, 4];
case 2:
requestBody = this.createTokenRequestBody(request);
headers = this.createTokenRequestHeaders();
thumbprint = {
clientId: this.config.authOptions.clientId,
authority: request.authority,
scopes: request.scopes,
claims: request.claims,
authenticationScheme: request.authenticationScheme,
resourceRequestMethod: request.resourceRequestMethod,
resourceRequestUri: request.resourceRequestUri,
shrClaims: request.shrClaims,
sshKid: request.sshKid
};
reqTimestamp = TimeUtils.nowSeconds();
return [4 /*yield*/, this.executePostToTokenEndpoint(authority.tokenEndpoint, requestBody, headers, thumbprint)];
case 3:
response = _a.sent();
serverTokenResponse = response.body;
_a.label = 4;
case 4:
responseHandler = new ResponseHandler(this.config.authOptions.clientId, this.cacheManager, this.cryptoUtils, this.logger, this.config.serializableCache, this.config.persistencePlugin);
responseHandler.validateTokenResponse(serverTokenResponse);
return [4 /*yield*/, responseHandler.handleServerTokenResponse(serverTokenResponse, this.authority, reqTimestamp, request)];
case 5:
tokenResponse = _a.sent();
return [2 /*return*/, tokenResponse];
}
});
});
};
/**
* generate the request to the server in the acceptable format
* @param request
*/
ClientCredentialClient.prototype.createTokenRequestBody = function (request) {
var parameterBuilder = new RequestParameterBuilder();
parameterBuilder.addClientId(this.config.authOptions.clientId);
parameterBuilder.addScopes(request.scopes, false);
parameterBuilder.addGrantType(GrantType.CLIENT_CREDENTIALS_GRANT);
parameterBuilder.addLibraryInfo(this.config.libraryInfo);
parameterBuilder.addApplicationTelemetry(this.config.telemetry.application);
parameterBuilder.addThrottling();
if (this.serverTelemetryManager) {
parameterBuilder.addServerTelemetry(this.serverTelemetryManager);
}
var correlationId = request.correlationId || this.config.cryptoInterface.createNewGuid();
parameterBuilder.addCorrelationId(correlationId);
if (this.config.clientCredentials.clientSecret) {
parameterBuilder.addClientSecret(this.config.clientCredentials.clientSecret);
}
// Use clientAssertion from request, fallback to client assertion in base configuration
var clientAssertion = request.clientAssertion || this.config.clientCredentials.clientAssertion;
if (clientAssertion) {
parameterBuilder.addClientAssertion(clientAssertion.assertion);
parameterBuilder.addClientAssertionType(clientAssertion.assertionType);
}
if (!StringUtils.isEmptyObj(request.claims) || this.config.authOptions.clientCapabilities && this.config.authOptions.clientCapabilities.length > 0) {
parameterBuilder.addClaims(request.claims, this.config.authOptions.clientCapabilities);
}
return parameterBuilder.createQueryString();
};
return ClientCredentialClient;
}(BaseClient));
export { ClientCredentialClient };
//# sourceMappingURL=ClientCredentialClient.js.map
{"version":3,"file":"ClientCredentialClient.js","sources":["../../src/client/ClientCredentialClient.ts"],"sourcesContent":["/*\n * Copyright (c) Microsoft Corporation. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { ClientConfiguration } from \"../config/ClientConfiguration\";\nimport { BaseClient } from \"./BaseClient\";\nimport { Authority } from \"../authority/Authority\";\nimport { RequestParameterBuilder } from \"../request/RequestParameterBuilder\";\nimport { ScopeSet } from \"../request/ScopeSet\";\nimport { GrantType , CredentialType, CacheOutcome, Constants, AuthenticationScheme } from \"../utils/Constants\";\nimport { ResponseHandler } from \"../response/ResponseHandler\";\nimport { AuthenticationResult } from \"../response/AuthenticationResult\";\nimport { CommonClientCredentialRequest } from \"../request/CommonClientCredentialRequest\";\nimport { CredentialFilter, CredentialCache } from \"../cache/utils/CacheTypes\";\nimport { AccessTokenEntity } from \"../cache/entities/AccessTokenEntity\";\nimport { TimeUtils } from \"../utils/TimeUtils\";\nimport { StringUtils } from \"../utils/StringUtils\";\nimport { RequestThumbprint } from \"../network/RequestThumbprint\";\nimport { ClientAuthError } from \"../error/ClientAuthError\";\nimport { ServerAuthorizationTokenResponse } from \"../response/ServerAuthorizationTokenResponse\";\nimport { IAppTokenProvider } from \"../config/AppTokenProvider\";\n\n/**\n * OAuth2.0 client credential grant\n */\nexport class ClientCredentialClient extends BaseClient {\n\n private scopeSet: ScopeSet;\n private readonly appTokenProvider?: IAppTokenProvider;\n\n constructor(configuration: ClientConfiguration, appTokenProvider?: IAppTokenProvider) {\n super(configuration);\n this.appTokenProvider = appTokenProvider;\n }\n\n /**\n * Public API to acquire a token with ClientCredential Flow for Confidential clients\n * @param request\n */\n public async acquireToken(request: CommonClientCredentialRequest): Promise<AuthenticationResult | null> {\n\n this.scopeSet = new ScopeSet(request.scopes || []);\n\n if (request.skipCache) {\n return await this.executeTokenRequest(request, this.authority);\n }\n\n const cachedAuthenticationResult = await this.getCachedAuthenticationResult(request);\n if (cachedAuthenticationResult) {\n return cachedAuthenticationResult;\n } else {\n return await this.executeTokenRequest(request, this.authority);\n }\n }\n\n /**\n * looks up cache if the tokens are cached already\n */\n private async getCachedAuthenticationResult(request: CommonClientCredentialRequest): Promise<AuthenticationResult | null> {\n \n const cachedAccessToken = this.readAccessTokenFromCache();\n\n if (!cachedAccessToken) {\n this.serverTelemetryManager?.setCacheOutcome(CacheOutcome.NO_CACHED_ACCESS_TOKEN);\n return null;\n }\n\n if (TimeUtils.isTokenExpired(cachedAccessToken.expiresOn, this.config.systemOptions.tokenRenewalOffsetSeconds)) {\n this.serverTelemetryManager?.setCacheOutcome(CacheOutcome.CACHED_ACCESS_TOKEN_EXPIRED);\n return null;\n }\n\n return await ResponseHandler.generateAuthenticationResult(\n this.cryptoUtils,\n this.authority,\n {\n account: null,\n idToken: null,\n accessToken: cachedAccessToken,\n refreshToken: null,\n appMetadata: null\n },\n true,\n request\n );\n }\n\n /**\n * Reads access token from the cache\n * TODO: Move this call to cacheManager instead\n */\n private readAccessTokenFromCache(): AccessTokenEntity | null {\n const accessTokenFilter: CredentialFilter = {\n homeAccountId: Constants.EMPTY_STRING,\n environment: this.authority.canonicalAuthorityUrlComponents.HostNameAndPort,\n credentialType: CredentialType.ACCESS_TOKEN,\n clientId: this.config.authOptions.clientId,\n realm: this.authority.tenant,\n target: this.scopeSet.printScopesLowerCase()\n };\n const credentialCache: CredentialCache = this.cacheManager.getCredentialsFilteredBy(accessTokenFilter);\n const accessTokens = Object.keys(credentialCache.accessTokens).map(key => credentialCache.accessTokens[key]);\n if (accessTokens.length < 1) {\n return null;\n } else if (accessTokens.length > 1) {\n throw ClientAuthError.createMultipleMatchingTokensInCacheError();\n }\n return accessTokens[0] as AccessTokenEntity;\n }\n\n /**\n * Makes a network call to request the token from the service\n * @param request\n * @param authority\n */\n private async executeTokenRequest(request: CommonClientCredentialRequest, authority: Authority)\n : Promise<AuthenticationResult | null> {\n \n let serverTokenResponse: ServerAuthorizationTokenResponse;\n let reqTimestamp: number;\n\n if (this.appTokenProvider) {\n this.logger.info(\"Using appTokenProvider extensibility.\");\n\n const appTokenPropviderParameters = {\n correlationId: request.correlationId,\n tenantId: this.config.authOptions.authority.tenant,\n scopes: request.scopes,\n claims: request.claims,\n };\n\n reqTimestamp = TimeUtils.nowSeconds();\n const appTokenProviderResult = await this.appTokenProvider(appTokenPropviderParameters);\n\n serverTokenResponse = {\n access_token: appTokenProviderResult.accessToken, \n expires_in: appTokenProviderResult.expiresInSeconds,\n refresh_in: appTokenProviderResult.refreshInSeconds,\n token_type : AuthenticationScheme.BEARER\n };\n } else {\n const requestBody = this.createTokenRequestBody(request);\n const headers: Record<string, string> = this.createTokenRequestHeaders();\n const thumbprint: RequestThumbprint = {\n clientId: this.config.authOptions.clientId,\n authority: request.authority,\n scopes: request.scopes,\n claims: request.claims,\n authenticationScheme: request.authenticationScheme,\n resourceRequestMethod: request.resourceRequestMethod,\n resourceRequestUri: request.resourceRequestUri,\n shrClaims: request.shrClaims,\n sshKid: request.sshKid\n };\n \n reqTimestamp = TimeUtils.nowSeconds();\n const response = await this.executePostToTokenEndpoint(authority.tokenEndpoint, requestBody, headers, thumbprint);\n serverTokenResponse = response.body;\n }\n\n const responseHandler = new ResponseHandler(\n this.config.authOptions.clientId,\n this.cacheManager,\n this.cryptoUtils,\n this.logger,\n this.config.serializableCache,\n this.config.persistencePlugin\n );\n\n responseHandler.validateTokenResponse(serverTokenResponse);\n \n const tokenResponse = await responseHandler.handleServerTokenResponse(\n serverTokenResponse,\n this.authority,\n reqTimestamp,\n request\n );\n\n return tokenResponse;\n }\n\n /**\n * generate the request to the server in the acceptable format\n * @param request\n */\n private createTokenRequestBody(request: CommonClientCredentialRequest): string {\n const parameterBuilder = new RequestParameterBuilder();\n\n parameterBuilder.addClientId(this.config.authOptions.clientId);\n\n parameterBuilder.addScopes(request.scopes, false);\n\n parameterBuilder.addGrantType(GrantType.CLIENT_CREDENTIALS_GRANT);\n\n parameterBuilder.addLibraryInfo(this.config.libraryInfo);\n parameterBuilder.addApplicationTelemetry(this.config.telemetry.application);\n\n parameterBuilder.addThrottling();\n \n if (this.serverTelemetryManager) {\n parameterBuilder.addServerTelemetry(this.serverTelemetryManager);\n }\n\n const correlationId = request.correlationId || this.config.cryptoInterface.createNewGuid();\n parameterBuilder.addCorrelationId(correlationId);\n\n if (this.config.clientCredentials.clientSecret) {\n parameterBuilder.addClientSecret(this.config.clientCredentials.clientSecret);\n }\n\n // Use clientAssertion from request, fallback to client assertion in base configuration\n const clientAssertion = request.clientAssertion || this.config.clientCredentials.clientAssertion;\n\n if (clientAssertion) {\n parameterBuilder.addClientAssertion(clientAssertion.assertion);\n parameterBuilder.addClientAssertionType(clientAssertion.assertionType);\n }\n\n if (!StringUtils.isEmptyObj(request.claims) || this.config.authOptions.clientCapabilities && this.config.authOptions.clientCapabilities.length > 0) {\n parameterBuilder.addClaims(request.claims, this.config.authOptions.clientCapabilities);\n }\n\n return parameterBuilder.createQueryString();\n }\n}\n"],"names":[],"mappings":";;;;;;;;;;;;AAAA;;;AAGG;AAoBH;;AAEG;AACH,IAAA,sBAAA,kBAAA,UAAA,MAAA,EAAA;IAA4C,SAAU,CAAA,sBAAA,EAAA,MAAA,CAAA,CAAA;IAKlD,SAAY,sBAAA,CAAA,aAAkC,EAAE,gBAAoC,EAAA;QAApF,IACI,KAAA,GAAA,MAAA,CAAA,IAAA,CAAA,IAAA,EAAM,aAAa,CAAC,IAEvB,IAAA,CAAA;AADG,QAAA,KAAI,CAAC,gBAAgB,GAAG,gBAAgB,CAAC;;KAC5C;AAED;;;AAGG;IACU,sBAAY,CAAA,SAAA,CAAA,YAAA,GAAzB,UAA0B,OAAsC,EAAA;;;;;;AAE5D,wBAAA,IAAI,CAAC,QAAQ,GAAG,IAAI,QAAQ,CAAC,OAAO,CAAC,MAAM,IAAI,EAAE,CAAC,CAAC;6BAE/C,OAAO,CAAC,SAAS,EAAjB,OAAiB,CAAA,CAAA,YAAA,CAAA,CAAA,CAAA;wBACV,O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C;;;;OAIG;IACU,YAAY,CAAC,OAAO,EAAE,uBAAuB,GAAG,OAAO,CAAC,oBAAoB,GAAG,IAAI,CAAC;IA2BjG;;;OAGG;YACW,aAAa;IAkB3B;;;;;OAKG;YACW,sCAAsC;IAkCpD;;OAEG;IACH,OAAO,CAAC,iBAAiB;IAczB;;;;OAIG;IACH,OAAO,CAAC,eAAe;IAqBvB;;;;;OAKG;YACW,0BAA0B;IA0DxC;;;;OAIG;IACH,OAAO,CAAC,sBAAsB;CAwBjC"}
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment