Skip to content

[msal-common] Configuration and Client #1325

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

Merged
merged 17 commits into from
Mar 17, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion lerna.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"lerna": "3.16.4",
"command": {
"run": {
"scope": ["msal", "@azure/msal-common", "@azure/msal-browser", "@azure/msal-angular"]
"scope": ["msal", "@azure/msal-common", "@azure/msal-browser", "@azure/msal-angular", "@azure/msal-node"]
}
},
"packages": [
Expand Down
Binary file added lib/.DS_Store
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
import { Authority } from "./Authority";
import { OpenIdConfigResponse } from "./OpenIdConfigResponse";
import { AuthorityType } from "./AuthorityType";
import { AADTrustedHostList, Constants } from "../../utils/Constants";
import { INetworkModule } from "../../network/INetworkModule";
import { AADTrustedHostList, Constants } from "./../utils/Constants";
import { INetworkModule } from "./../network/INetworkModule";

/**
* The AadAuthority class extends the Authority class and adds functionality specific to the Azure AD OAuth Authority.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
*/
import { AuthorityType } from "./AuthorityType";
import { TenantDiscoveryResponse } from "./TenantDiscoveryResponse";
import { UrlString } from "../../url/UrlString";
import { IUri } from "../../url/IUri";
import { ClientAuthError } from "../../error/ClientAuthError";
import { INetworkModule } from "../../network/INetworkModule";
import { UrlString } from "./../url/UrlString";
import { IUri } from "./../url/IUri";
import { ClientAuthError } from "./../error/ClientAuthError";
import { INetworkModule } from "./../network/INetworkModule";

/**
* The authority class validates the authority URIs used by the user, and retrieves the OpenID Configuration Data from the
Expand Down Expand Up @@ -107,7 +107,7 @@ export abstract class Authority {

/**
* Replaces tenant in url path with current tenant. Defaults to common.
* @param urlString
* @param urlString
*/
private replaceTenant(urlString: string): string {
return urlString.replace("{tenant}", this.tenant);
Expand Down Expand Up @@ -136,7 +136,7 @@ export abstract class Authority {

/**
* Gets OAuth endpoints from the given OpenID configuration endpoint.
* @param openIdConfigurationEndpoint
* @param openIdConfigurationEndpoint
*/
private async discoverEndpoints(openIdConfigurationEndpoint: string): Promise<TenantDiscoveryResponse> {
return this.networkInterface.sendGetRequestAsync<TenantDiscoveryResponse>(openIdConfigurationEndpoint);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
import { Authority } from "./Authority";
import { AadAuthority } from "./AadAuthority";
import { AuthorityType } from "./AuthorityType";
import { ClientConfigurationError } from "../../error/ClientConfigurationError";
import { ClientAuthError } from "../../error/ClientAuthError";
import { INetworkModule } from "../../network/INetworkModule";
import { StringUtils } from "../../utils/StringUtils";
import { UrlString } from "../../url/UrlString";
import { ClientConfigurationError } from "../error/ClientConfigurationError";
import { ClientAuthError } from "./../error/ClientAuthError";
import { INetworkModule } from "./../network/INetworkModule";
import { StringUtils } from "./../utils/StringUtils";
import { UrlString } from "./../url/UrlString";

export class AuthorityFactory {

Expand Down
8 changes: 4 additions & 4 deletions lib/msal-common/src/cache/CacheHelpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import { AccessTokenCacheItem } from "./AccessTokenCacheItem";
import { AccessTokenKey } from "./AccessTokenKey";
import { AccessTokenValue } from "./AccessTokenValue";
import { ICacheStorage } from "./ICacheStorage";
import { Account } from "../auth/Account";
import { Authority } from "../auth/authority/Authority";
import { Account } from "../account/Account";
import { Authority } from "../authority/Authority";
import { ServerCodeRequestParameters } from "../server/ServerCodeRequestParameters";
import { ClientAuthError } from "../error/ClientAuthError";
import { StringUtils } from "../utils/StringUtils";
Expand Down Expand Up @@ -44,7 +44,7 @@ export class CacheHelpers {

/**
* Create Nonce key to cache nonce
* @param state
* @param state
*/
generateNonceKey(state: string): string {
return `${TemporaryCacheKeys.NONCE_IDTOKEN}${Constants.RESOURCE_DELIM}${state}`;
Expand Down Expand Up @@ -97,7 +97,7 @@ export class CacheHelpers {

/**
* Reset all temporary cache items
* @param state
* @param state
*/
resetTempCacheItems(state?: string): void {
// check state and remove associated cache items
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,22 @@
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License.
*/
import { ModuleConfiguration, buildModuleConfiguration } from "../config/ModuleConfiguration";
import { AuthenticationParameters } from "../../request/AuthenticationParameters";
import { TokenRenewParameters } from "../../request/TokenRenewParameters";
import { CodeResponse } from "../../response/CodeResponse";
import { TokenResponse } from "../../response/TokenResponse";
import { ICacheStorage } from "../../cache/ICacheStorage";
import { CacheHelpers } from "../../cache/CacheHelpers";
import { INetworkModule } from "../../network/INetworkModule";
import { ICrypto } from "../../crypto/ICrypto";
import { Account } from "../../auth/Account";
import { Authority } from "../../auth/authority/Authority";
import { IdToken } from "../../auth/IdToken";
import { buildClientInfo } from "../../auth/ClientInfo";
import { StringUtils } from "../../utils/StringUtils";
import { Logger } from "../../logger/Logger";
import { PersistentCacheKeys } from "../../utils/Constants";
import { Configuration, buildConfiguration } from "../config/Configuration";
import { AuthenticationParameters } from "../request/AuthenticationParameters";
import { TokenRenewParameters } from "../request/TokenRenewParameters";
import { CodeResponse } from "../response/CodeResponse";
import { TokenResponse } from "../response/TokenResponse";
import { ICacheStorage } from "../cache/ICacheStorage";
import { CacheHelpers } from "../cache/CacheHelpers";
import { INetworkModule } from "../network/INetworkModule";
import { ICrypto } from "../crypto/ICrypto";
import { Account } from "../account/Account";
import { Authority } from "../authority/Authority";
import { IdToken } from "../account/IdToken";
import { buildClientInfo } from "../account/ClientInfo";
import { StringUtils } from "../utils/StringUtils";
import { Logger } from "../logger/Logger";
import { PersistentCacheKeys } from "../utils/Constants";

/**
* @hidden
Expand All @@ -30,19 +30,19 @@ export type ResponseStateInfo = {
};

/**
* AuthModule class
*
* BaseClient class
*
* Parent object instance which will construct requests to send to and handle responses from the Microsoft STS using the authorization code flow.
*
*
*/
export abstract class AuthModule {
export abstract class BaseClient {

// Logger object
public logger: Logger;

// Application config
private config: ModuleConfiguration;
private config: Configuration;

// Crypto Interface
protected cryptoObj: ICrypto;

Expand All @@ -61,9 +61,9 @@ export abstract class AuthModule {
// Default authority object
protected defaultAuthorityInstance: Authority;

constructor(configuration: ModuleConfiguration) {
constructor(configuration: Configuration) {
// Set the configuration
this.config = buildModuleConfiguration(configuration);
this.config = buildConfiguration(configuration);

// Initialize the logger
this.logger = new Logger(this.config.loggerOptions);
Expand All @@ -84,52 +84,52 @@ export abstract class AuthModule {
// #region Abstract Functions

/**
* Creates a url for logging in a user. This will by default append the client id to the list of scopes,
* Creates a url for logging in a user. This will by default append the client id to the list of scopes,
* allowing you to retrieve an id token in the subsequent code exchange. Also performs validation of the request parameters.
* Including any SSO parameters (account, sid, login_hint) will short circuit the authentication and allow you to retrieve a code without interaction.
* @param request
* @param request
*/
abstract async createLoginUrl(request: AuthenticationParameters): Promise<string>;

/**
* Creates a url for logging in a user. Also performs validation of the request parameters.
* Including any SSO parameters (account, sid, login_hint) will short circuit the authentication and allow you to retrieve a code without interaction.
* @param request
* @param request
*/
abstract async createAcquireTokenUrl(request: AuthenticationParameters): Promise<string>;

/**
* 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
* @param hashFragment
*/
abstract handleFragmentResponse(hashFragment: string): CodeResponse;

/**
* Given an authorization code, it will perform a token exchange using cached values from a previous call to
* createLoginUrl() or createAcquireTokenUrl(). You must call this AFTER using one of those APIs first. You should
* also use the handleFragmentResponse() API to pass the codeResponse to this function afterwards.
* @param codeResponse
* @param codeResponse
*/
abstract async acquireToken(codeResponse: CodeResponse): Promise<TokenResponse>;

/**
* Retrieves a token from cache if it is still valid, or uses the cached refresh token to renew
* the given token and returns the renewed token. Will throw an error if login is not completed (unless
* id tokens are not being renewed).
* @param request
* @param request
*/
abstract async renewToken(request: TokenRenewParameters): Promise<TokenResponse>;

/**
* Use 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
* @param authorityUri
*/
abstract async logout(authorityUri?: string): Promise<string>;

// #endregion

// #region Getters and Setters

/**
Expand Down
Loading