Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move node clients from msal-common to msal-node #5788

Merged
merged 10 commits into from
Mar 31, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
- Fix imports.
- Fix unit tests.
konstantin-msft committed Mar 31, 2023
commit 46ffb346fc7252a891615032206774a71c95d4b7
9 changes: 6 additions & 3 deletions lib/msal-common/src/index.ts
Original file line number Diff line number Diff line change
@@ -11,6 +11,7 @@
export { AuthorizationCodeClient} from "./client/AuthorizationCodeClient";
export { RefreshTokenClient } from "./client/RefreshTokenClient";
export { SilentFlowClient } from "./client/SilentFlowClient";
export { BaseClient } from "./client/BaseClient";
export { AuthOptions, SystemOptions, LoggerOptions, DEFAULT_SYSTEM_OPTIONS, AzureCloudOptions, ApplicationTelemetry } from "./config/ClientConfiguration";
export { IAppTokenProvider, AppTokenProviderParameters, AppTokenProviderResult } from "./config/AppTokenProvider";
export { ClientConfiguration } from "./config/ClientConfiguration";
@@ -32,7 +33,7 @@ export { ProtocolMode } from "./authority/ProtocolMode";
export { INativeBrokerPlugin } from "./broker/nativeBroker/INativeBrokerPlugin";
// Cache
export { CacheManager, DefaultStorageClass } from "./cache/CacheManager";
export { AccountCache, AccessTokenCache, IdTokenCache, RefreshTokenCache, AppMetadataCache, ValidCacheType, ValidCredentialType } from "./cache/utils/CacheTypes";
export { AccountCache, AccessTokenCache, IdTokenCache, RefreshTokenCache, AppMetadataCache, CredentialCache, CredentialFilter, ValidCacheType, ValidCredentialType } from "./cache/utils/CacheTypes";
export { CacheRecord } from "./cache/entities/CacheRecord";
export { CredentialEntity } from "./cache/entities/CredentialEntity";
export { AppMetadataEntity } from "./cache/entities/AppMetadataEntity";
@@ -71,6 +72,7 @@ export { CommonEndSessionRequest } from "./request/CommonEndSessionRequest";
export { CommonUsernamePasswordRequest } from "./request/CommonUsernamePasswordRequest";
export { NativeRequest } from "./request/NativeRequest";
export { NativeSignOutRequest } from "./request/NativeSignOutRequest";
export { RequestParameterBuilder } from "./request/RequestParameterBuilder";
// Response
export { AzureRegion } from "./authority/AzureRegion";
export { AzureRegionConfiguration } from "./authority/AzureRegionConfiguration";
@@ -79,7 +81,8 @@ export { AuthorizationCodePayload } from "./response/AuthorizationCodePayload";
export { ServerAuthorizationCodeResponse } from "./response/ServerAuthorizationCodeResponse";
export { ServerAuthorizationTokenResponse } from "./response/ServerAuthorizationTokenResponse";
export { ExternalTokenResponse } from "./response/ExternalTokenResponse";
export { DeviceCodeResponse } from "./response/DeviceCodeResponse";
export { DeviceCodeResponse, ServerDeviceCodeResponse } from "./response/DeviceCodeResponse";
export { ResponseHandler } from "./response/ResponseHandler";
export { ScopeSet } from "./request/ScopeSet";
export { AuthenticationHeaderParser } from "./request/AuthenticationHeaderParser";
// Logger Callback
@@ -91,7 +94,7 @@ export { ServerError } from "./error/ServerError";
export { ClientAuthError, ClientAuthErrorMessage } from "./error/ClientAuthError";
export { ClientConfigurationError, ClientConfigurationErrorMessage } from "./error/ClientConfigurationError";
// Constants and Utils
export { Constants, OIDC_DEFAULT_SCOPES, PromptValue, PersistentCacheKeys, ResponseMode, CacheSchemaType, CredentialType, CacheType, CacheAccountType, AuthenticationScheme, CodeChallengeMethodValues, SSOTypes, PasswordGrantConstants, ThrottlingConstants, ClaimsRequestKeys, HeaderNames, AADServerParamKeys, Errors, THE_FAMILY_ID, ONE_DAY_IN_MS } from "./utils/Constants";
export { Constants, OIDC_DEFAULT_SCOPES, PromptValue, PersistentCacheKeys, ResponseMode, CacheOutcome, CacheSchemaType, CredentialType, CacheType, CacheAccountType, AuthenticationScheme, CodeChallengeMethodValues, SSOTypes, PasswordGrantConstants, ThrottlingConstants, ClaimsRequestKeys, HeaderNames, AADServerParamKeys, Errors, THE_FAMILY_ID, ONE_DAY_IN_MS, GrantType } from "./utils/Constants";
export { StringUtils } from "./utils/StringUtils";
export { StringDict } from "./utils/MsalTypes";
export { ProtocolUtils, RequestStateObject, LibraryStateObject } from "./utils/ProtocolUtils";
4 changes: 3 additions & 1 deletion lib/msal-node/package.json
Original file line number Diff line number Diff line change
@@ -50,13 +50,15 @@
"@types/jsonwebtoken": "^8.5.5",
"@types/node": "^13.13.4",
"@types/uuid": "^7.0.0",
"@types/sinon": "^7.5.0",
"husky": "^4.2.3",
"jest": "^29.5.0",
"rollup": "^3.20.1",
"ts-jest": "^29.0.5",
"tslib": "^1.10.0",
"typescript": "^4.9.5",
"yargs": "^17.3.1"
"yargs": "^17.3.1",
"sinon": "^7.5.0"
},
"dependencies": {
"@azure/msal-common": "^10.0.0",
2 changes: 1 addition & 1 deletion lib/msal-node/src/client/ClientApplication.ts
Original file line number Diff line number Diff line change
@@ -20,7 +20,6 @@ import {
CommonAuthorizationCodeRequest,
CommonAuthorizationUrlRequest,
CommonUsernamePasswordRequest,
UsernamePasswordClient,
AuthenticationScheme,
ResponseMode,
AuthorityOptions,
@@ -45,6 +44,7 @@ import { SilentFlowRequest } from "../request/SilentFlowRequest";
import { version, name } from "../packageMetadata";
import { UsernamePasswordRequest } from "../request/UsernamePasswordRequest";
import { NodeAuthError } from "../error/NodeAuthError";
import { UsernamePasswordClient } from "./UsernamePasswordClient";

/**
* Base abstract class for all ClientApplications - public and confidential
28 changes: 9 additions & 19 deletions lib/msal-node/src/client/ClientCredentialClient.ts
Original file line number Diff line number Diff line change
@@ -3,24 +3,14 @@
* Licensed under the MIT License.
*/

import { ClientConfiguration } from "@azure/msal-common/src/config/ClientConfiguration";
import { BaseClient } from "@azure/msal-common/src/client/BaseClient";
import { Authority } from "@azure/msal-common/src/authority/Authority";
import { RequestParameterBuilder } from "@azure/msal-common/src/request/RequestParameterBuilder";
import { ScopeSet } from "@azure/msal-common/src/request/ScopeSet";
import { GrantType , CredentialType, CacheOutcome, Constants, AuthenticationScheme } from "@azure/msal-common/src/utils/Constants";
import { ResponseHandler } from "@azure/msal-common/src/response/ResponseHandler";
import { AuthenticationResult } from "@azure/msal-common/src/response/AuthenticationResult";
import { CommonClientCredentialRequest } from "@azure/msal-common/src/request/CommonClientCredentialRequest";
import { CredentialFilter, CredentialCache } from "@azure/msal-common/src/cache/utils/CacheTypes";
import { AccessTokenEntity } from "@azure/msal-common/src/cache/entities/AccessTokenEntity";
import { TimeUtils } from "@azure/msal-common/src/utils/TimeUtils";
import { StringUtils } from "@azure/msal-common/src/utils/StringUtils";
import { RequestThumbprint } from "@azure/msal-common/src/network/RequestThumbprint";
import { ClientAuthError } from "@azure/msal-common/src/error/ClientAuthError";
import { ServerAuthorizationTokenResponse } from "@azure/msal-common/src/response/ServerAuthorizationTokenResponse";
import { IAppTokenProvider } from "@azure/msal-common/src/config/AppTokenProvider";
import { UrlString } from "@azure/msal-common/src/url/UrlString";
import {
AccessTokenEntity,
AuthenticationResult, AuthenticationScheme, Authority, BaseClient, CacheOutcome, ClientAuthError,
ClientConfiguration,
CommonClientCredentialRequest, Constants, CredentialCache, CredentialFilter, CredentialType, GrantType,
IAppTokenProvider, RequestParameterBuilder, RequestThumbprint, ResponseHandler,
ScopeSet, ServerAuthorizationTokenResponse, StringUtils, TimeUtils, UrlString
} from "@azure/msal-common";

/**
* OAuth2.0 client credential grant
@@ -138,7 +128,7 @@ export class ClientCredentialClient extends BaseClient {
access_token: appTokenProviderResult.accessToken,
expires_in: appTokenProviderResult.expiresInSeconds,
refresh_in: appTokenProviderResult.refreshInSeconds,
token_type : AuthenticationScheme.BEARER
token_type: AuthenticationScheme.BEARER
};
} else {
const queryParametersString = this.createTokenQueryParameters(request);
4 changes: 2 additions & 2 deletions lib/msal-node/src/client/ConfidentialClientApplication.ts
Original file line number Diff line number Diff line change
@@ -8,8 +8,6 @@ import { Configuration } from "../config/Configuration";
import { ClientAssertion } from "./ClientAssertion";
import { Constants as NodeConstants, ApiId, REGION_ENVIRONMENT_VARIABLE } from "../utils/Constants";
import {
ClientCredentialClient,
OnBehalfOfClient,
CommonClientCredentialRequest,
CommonOnBehalfOfRequest,
AuthenticationResult,
@@ -24,6 +22,8 @@ import {
import { IConfidentialClientApplication } from "./IConfidentialClientApplication";
import { OnBehalfOfRequest } from "../request/OnBehalfOfRequest";
import { ClientCredentialRequest } from "../request/ClientCredentialRequest";
import { ClientCredentialClient } from "./ClientCredentialClient";
import { OnBehalfOfClient } from "./OnBehalfOfClient";

/**
* This class is to be used to acquire tokens for confidential client applications (webApp, webAPI). Confidential client applications
34 changes: 19 additions & 15 deletions lib/msal-node/src/client/DeviceCodeClient.ts
Original file line number Diff line number Diff line change
@@ -3,21 +3,25 @@
* Licensed under the MIT License.
*/

import { DeviceCodeResponse, ServerDeviceCodeResponse } from "@azure/msal-common/src/response/DeviceCodeResponse";
import { BaseClient } from "@azure/msal-common/src/client/BaseClient";
import { CommonDeviceCodeRequest } from "@azure/msal-common/src/request/CommonDeviceCodeRequest";
import { ClientAuthError } from "@azure/msal-common/src/error/ClientAuthError";
import { RequestParameterBuilder } from "@azure/msal-common/src/request/RequestParameterBuilder";
import { Constants, GrantType } from "@azure/msal-common/src/utils/Constants";
import { ClientConfiguration } from "@azure/msal-common/src/config/ClientConfiguration";
import { TimeUtils } from "@azure/msal-common/src/utils/TimeUtils";
import { ServerAuthorizationTokenResponse } from "@azure/msal-common/src/response/ServerAuthorizationTokenResponse";
import { ResponseHandler } from "@azure/msal-common/src/response/ResponseHandler";
import { AuthenticationResult } from "@azure/msal-common/src/response/AuthenticationResult";
import { StringUtils } from "@azure/msal-common/src/utils/StringUtils";
import { RequestThumbprint } from "@azure/msal-common/src/network/RequestThumbprint";
import { ServerError } from "@azure/msal-common/src/error/ServerError";
import { UrlString } from "@azure/msal-common/src/url/UrlString";
import {
AuthenticationResult,
BaseClient,
ClientAuthError,
ClientConfiguration,
CommonDeviceCodeRequest,
Constants,
DeviceCodeResponse,
GrantType,
RequestParameterBuilder,
RequestThumbprint,
ResponseHandler,
ServerAuthorizationTokenResponse,
ServerDeviceCodeResponse,
ServerError,
StringUtils,
TimeUtils,
UrlString
} from "@azure/msal-common";

/**
* OAuth2.0 Device code client
51 changes: 29 additions & 22 deletions lib/msal-node/src/client/OnBehalfOfClient.ts
Original file line number Diff line number Diff line change
@@ -3,25 +3,32 @@
* Licensed under the MIT License.
*/

import { ClientConfiguration } from "@azure/msal-common/src/config/ClientConfiguration";
import { BaseClient } from "@azure/msal-common/src/client/BaseClient";
import { Authority } from "@azure/msal-common/src/authority/Authority";
import { RequestParameterBuilder } from "@azure/msal-common/src/request/RequestParameterBuilder";
import { ScopeSet } from "@azure/msal-common/src/request/ScopeSet";
import { GrantType, AADServerParamKeys , CredentialType, Constants, CacheOutcome, AuthenticationScheme } from "@azure/msal-common/src/utils/Constants";
import { ResponseHandler } from "@azure/msal-common/src/response/ResponseHandler";
import { AuthenticationResult } from "@azure/msal-common/src/response/AuthenticationResult";
import { CommonOnBehalfOfRequest } from "@azure/msal-common/src/request/CommonOnBehalfOfRequest";
import { TimeUtils } from "@azure/msal-common/src/utils/TimeUtils";
import { CredentialFilter, CredentialCache } from "@azure/msal-common/src/cache/utils/CacheTypes";
import { AccessTokenEntity } from "@azure/msal-common/src/cache/entities/AccessTokenEntity";
import { IdTokenEntity } from "@azure/msal-common/src/cache/entities/IdTokenEntity";
import { AccountEntity } from "@azure/msal-common/src/cache/entities/AccountEntity";
import { AuthToken } from "@azure/msal-common/src/account/AuthToken";
import { ClientAuthError } from "@azure/msal-common/src/error/ClientAuthError";
import { RequestThumbprint } from "@azure/msal-common/src/network/RequestThumbprint";
import { AccountInfo } from "@azure/msal-common/src/account/AccountInfo";
import { UrlString } from "@azure/msal-common/src/url/UrlString";
import {
AADServerParamKeys,
AccessTokenEntity,
AccountEntity,
AccountInfo,
AuthenticationResult,
AuthenticationScheme,
Authority,
AuthToken,
BaseClient,
CacheOutcome,
ClientAuthError,
ClientConfiguration,
CommonOnBehalfOfRequest,
Constants,
CredentialCache,
CredentialFilter,
CredentialType, GrantType,
IdTokenEntity,
RequestParameterBuilder,
RequestThumbprint,
ResponseHandler,
ScopeSet,
TimeUtils,
UrlString
} from "@azure/msal-common";

/**
* On-Behalf-Of client
@@ -82,7 +89,7 @@ export class OnBehalfOfClient extends BaseClient {
}

// fetch the idToken from cache
const cachedIdToken = this.readIdTokenFromCacheForOBO(request, cachedAccessToken.homeAccountId);
const cachedIdToken = this.readIdTokenFromCacheForOBO(cachedAccessToken.homeAccountId);
let idTokenObject: AuthToken | undefined;
let cachedAccount: AccountEntity | null = null;
if (cachedIdToken) {
@@ -122,9 +129,9 @@ export class OnBehalfOfClient extends BaseClient {
/**
* read idtoken from cache, this is a specific implementation for OBO as the requirements differ from a generic lookup in the cacheManager
* Certain use cases of OBO flow do not expect an idToken in the cache/or from the service
* @param request
* @param atHomeAccountId {string}
*/
private readIdTokenFromCacheForOBO(request: CommonOnBehalfOfRequest, atHomeAccountId: string): IdTokenEntity | null {
private readIdTokenFromCacheForOBO(atHomeAccountId: string): IdTokenEntity | null {

const idTokenFilter: CredentialFilter = {
homeAccountId: atHomeAccountId,
2 changes: 1 addition & 1 deletion lib/msal-node/src/client/PublicClientApplication.ts
Original file line number Diff line number Diff line change
@@ -5,7 +5,6 @@

import { ApiId } from "../utils/Constants";
import {
DeviceCodeClient,
AuthenticationResult,
CommonDeviceCodeRequest,
AuthError,
@@ -25,6 +24,7 @@ import { InteractiveRequest } from "../request/InteractiveRequest";
import { NodeAuthError } from "../error/NodeAuthError";
import { LoopbackClient } from "../network/LoopbackClient";
import { ILoopbackClient } from "../network/ILoopbackClient";
import { DeviceCodeClient } from "./DeviceCodeClient";

/**
* This class is to be used to acquire tokens for public client applications (desktop, mobile). Public client applications
33 changes: 18 additions & 15 deletions lib/msal-node/src/client/UsernamePasswordClient.ts
Original file line number Diff line number Diff line change
@@ -3,21 +3,24 @@
* Licensed under the MIT License.
*/

import { BaseClient } from "@azure/msal-common/src/client/BaseClient";
import { ClientConfiguration } from "@azure/msal-common/src/config/ClientConfiguration";
import { CommonUsernamePasswordRequest } from "@azure/msal-common/src/request/CommonUsernamePasswordRequest";
import { AuthenticationResult } from "@azure/msal-common/src/response/AuthenticationResult";
import { ResponseHandler } from "@azure/msal-common/src/response/ResponseHandler";
import { Authority } from "@azure/msal-common/src/authority/Authority";
import { NetworkResponse } from "@azure/msal-common/src/network/NetworkManager";
import { ServerAuthorizationTokenResponse } from "@azure/msal-common/src/response/ServerAuthorizationTokenResponse";
import { RequestParameterBuilder } from "@azure/msal-common/src/request/RequestParameterBuilder";
import { GrantType, HeaderNames } from "@azure/msal-common/src/utils/Constants";
import { StringUtils } from "@azure/msal-common/src/utils/StringUtils";
import { RequestThumbprint } from "@azure/msal-common/src/network/RequestThumbprint";
import { TimeUtils } from "@azure/msal-common/src/utils/TimeUtils";
import { CcsCredentialType } from "@azure/msal-common/src/account/CcsCredential";
import { UrlString } from "@azure/msal-common/src/url/UrlString";
import {
AuthenticationResult,
Authority,
BaseClient,
CcsCredentialType,
ClientConfiguration,
CommonUsernamePasswordRequest,
GrantType,
HeaderNames,
NetworkResponse,
RequestParameterBuilder,
RequestThumbprint,
ResponseHandler,
ServerAuthorizationTokenResponse,
StringUtils,
TimeUtils,
UrlString
} from "@azure/msal-common";

/**
* Oauth2.0 Password grant client
5 changes: 5 additions & 0 deletions lib/msal-node/src/index.ts
Original file line number Diff line number Diff line change
@@ -20,6 +20,11 @@ export { ILoopbackClient } from "./network/ILoopbackClient";
export { PublicClientApplication } from "./client/PublicClientApplication";
export { ConfidentialClientApplication } from "./client/ConfidentialClientApplication";
export { ClientApplication } from "./client/ClientApplication";
export { ClientCredentialClient } from "./client/ClientCredentialClient";
export { DeviceCodeClient } from "./client/DeviceCodeClient";
export { OnBehalfOfClient } from "./client/OnBehalfOfClient";
export { UsernamePasswordClient } from "./client/UsernamePasswordClient";

export { Configuration, buildAppConfiguration, NodeAuthOptions, NodeSystemOptions, CacheOptions } from "./config/Configuration";
export { ClientAssertion } from "./client/ClientAssertion";

Loading