Skip to content
Open
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
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,9 @@
"scripts": {
"docs": "typedoc",
"lint": "eslint src test --ext .js,.ts && tsc",
"test": "mocha test/unit test/unit/token test/unit/tracking-buffer",
"test": "mocha test/unit test/unit/authentication test/unit/token test/unit/tracking-buffer",
"test-integration": "mocha test/integration/",
"test-all": "mocha test/unit/ test/unit/token/ test/unit/tracking-buffer test/integration/",
"test-all": "mocha test/unit/ test/unit/authentication test/unit/token/ test/unit/tracking-buffer test/integration/",
"build": "rimraf lib && babel src --out-dir lib --extensions .js,.ts",
"prepublish": "npm run build",
"semantic-release": "semantic-release"
Expand Down
84 changes: 84 additions & 0 deletions src/authentication/authentication-types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
import { AzureActiveDirectoryAccessTokenAuthenticationType } from './azure-active-directory-access-token';
import { AzureActiveDirectoryMsiAppServiceAuthenticationType } from './azure-active-directory-msi-app-service';
import { AzureActiveDirectoryMsiVmAuthenticationType } from './azure-active-directory-msi-vm';
import { AzureActiveDirectoryPasswordAuthenticationType } from './azure-active-directory-password';
import { AzureActiveDirectoryServicePrincipalSecretType } from './azure-active-directory-service-principal-secret';
import { DefaultAuthenticationType } from './default';
import { NtlmAuthenticationType } from './ntlm';

export const SupportedAuthenticationTypes = Object.freeze([
AzureActiveDirectoryAccessTokenAuthenticationType,
AzureActiveDirectoryMsiAppServiceAuthenticationType,
AzureActiveDirectoryMsiVmAuthenticationType,
AzureActiveDirectoryPasswordAuthenticationType,
AzureActiveDirectoryServicePrincipalSecretType,
DefaultAuthenticationType,
NtlmAuthenticationType,
]);

/**
* Authentication types that requires FedAuth request
*/
export type FedAuthAuthenticationType = typeof AzureActiveDirectoryPasswordAuthenticationType |
typeof AzureActiveDirectoryMsiVmAuthenticationType |
typeof AzureActiveDirectoryMsiAppServiceAuthenticationType |
typeof AzureActiveDirectoryServicePrincipalSecretType;

/**
* Active Directory Authentication types
*/
export type AADAuthenticationType = FedAuthAuthenticationType
| typeof AzureActiveDirectoryAccessTokenAuthenticationType

/**
* All authentication types
*/
export type AuthenticationType = AADAuthenticationType
| typeof DefaultAuthenticationType
| typeof NtlmAuthenticationType;


/**
* Checks if authentication type requires FedAuth request
*
* @param {AuthenticationType} authenticationType
* @return {boolean}
*/
export function isSupportedAuthenticationType(authenticationType: AuthenticationType): boolean {
return SupportedAuthenticationTypes.includes(authenticationType);
}

/**
* Checks if authentication type requires FedAuth request
*
* @param {AuthenticationType} authenticationType
* @return {boolean}
*/
export function isFedAuthAuthenticationType(authenticationType: AuthenticationType): boolean {
switch (authenticationType) {
case AzureActiveDirectoryMsiAppServiceAuthenticationType:
case AzureActiveDirectoryMsiVmAuthenticationType:
case AzureActiveDirectoryPasswordAuthenticationType:
case AzureActiveDirectoryServicePrincipalSecretType:
return true;

default:
return false;
}
}

/**
* Checks if authentication type is AAD Authentication
*
* @param {AuthenticationType} authenticationType
* @return {boolean}
*/
export function isAADAuthenticationType(authenticationType: AuthenticationType): boolean {
switch (authenticationType) {
case AzureActiveDirectoryAccessTokenAuthenticationType:
return true;

default:
return isFedAuthAuthenticationType(authenticationType);
}
}
23 changes: 23 additions & 0 deletions src/authentication/authentication.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { AzureActiveDirectoryAccessTokenAuthentication } from './azure-active-directory-access-token';
import { AzureActiveDirectoryServicePrincipalSecret } from './azure-active-directory-service-principal-secret';
import { AzureActiveDirectoryPasswordAuthentication } from './azure-active-directory-password';
import { AzureActiveDirectoryMsiVmAuthentication } from './azure-active-directory-msi-vm';
import { AzureActiveDirectoryMsiAppServiceAuthentication } from './azure-active-directory-msi-app-service';
import { DefaultAuthentication } from './default';
import { NtlmAuthentication } from './ntlm';

/**
* FedAuth authentications
*/
export type FedAuthAuthentication = AzureActiveDirectoryPasswordAuthentication
| AzureActiveDirectoryMsiVmAuthentication
| AzureActiveDirectoryMsiAppServiceAuthentication
| AzureActiveDirectoryServicePrincipalSecret;

/**
* All supported authentications
*/
export type Authentication = FedAuthAuthentication
| AzureActiveDirectoryAccessTokenAuthentication
| DefaultAuthentication
| NtlmAuthentication;
39 changes: 39 additions & 0 deletions src/authentication/azure-active-directory-access-token.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
export const AzureActiveDirectoryAccessTokenAuthenticationType = 'azure-active-directory-access-token';

export interface AzureActiveDirectoryAccessTokenAuthentication {
type: typeof AzureActiveDirectoryAccessTokenAuthenticationType;
options: {
/**
* A user need to provide `token` which they retrived else where
* to forming the connection.
*/
token: string;
};
}

/**
* @param {AzureActiveDirectoryAccessTokenAuthentication} authentication
* @throws {TypeError}
*/
export function validateAADAccessTokenOptions(authentication: AzureActiveDirectoryAccessTokenAuthentication): void {
const { options } = authentication;

if (typeof options.token !== 'string') {
throw new TypeError('The "config.authentication.options.token" property must be of type string.');
}
}

/**
* @param {AzureActiveDirectoryAccessTokenAuthentication} authentication
* @return {AzureActiveDirectoryAccessTokenAuthentication}
*/
export function parseAADAccessTokenOptions(authentication: AzureActiveDirectoryAccessTokenAuthentication): AzureActiveDirectoryAccessTokenAuthentication {
const { options } = authentication;

return {
type: AzureActiveDirectoryAccessTokenAuthenticationType,
options: {
token: options.token,
},
};
}
61 changes: 61 additions & 0 deletions src/authentication/azure-active-directory-msi-app-service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
export const AzureActiveDirectoryMsiAppServiceAuthenticationType = 'azure-active-directory-msi-app-service';

export interface AzureActiveDirectoryMsiAppServiceAuthentication {
type: typeof AzureActiveDirectoryMsiAppServiceAuthenticationType;
options: {
/**
* If you user want to connect to an Azure app service using a specific client account
* they need to provide `clientId` asscoiate to their created idnetity.
*
* This is optional for retrieve token from azure web app service
*/
clientId?: string;
/**
* A msi app service environment need to provide `msiEndpoint` for retriving the accesstoken.
*/
msiEndpoint?: string;
/**
* A msi app service environment need to provide `msiSecret` for retriving the accesstoken.
*/
msiSecret?: string;
};
}


/**
* @param {AzureActiveDirectoryMsiAppServiceAuthentication} authentication
* @throws {TypeError}
*/
export function validateAADMsiAppServiceOptions(authentication: AzureActiveDirectoryMsiAppServiceAuthentication): void {
const { options } = authentication;

if (options.clientId !== undefined && typeof options.clientId !== 'string') {
throw new TypeError('The "config.authentication.options.clientId" property must be of type string.');
}

if (options.msiEndpoint !== undefined && typeof options.msiEndpoint !== 'string') {
throw new TypeError('The "config.authentication.options.msiEndpoint" property must be of type string.');
}

if (options.msiSecret !== undefined && typeof options.msiSecret !== 'string') {
throw new TypeError('The "config.authentication.options.msiSecret" property must be of type string.');
}

}

/**
* @param {AzureActiveDirectoryMsiAppServiceAuthentication} authentication
* @return {AzureActiveDirectoryMsiAppServiceAuthentication}
*/
export function parseAADMsiAppServiceOptions(authentication: AzureActiveDirectoryMsiAppServiceAuthentication): AzureActiveDirectoryMsiAppServiceAuthentication {
const { options } = authentication;

return {
type: AzureActiveDirectoryMsiAppServiceAuthenticationType,
options: {
clientId: options.clientId,
msiEndpoint: options.msiEndpoint,
msiSecret: options.msiSecret,
},
};
}
52 changes: 52 additions & 0 deletions src/authentication/azure-active-directory-msi-vm.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
export const AzureActiveDirectoryMsiVmAuthenticationType = 'azure-active-directory-msi-vm';

export interface AzureActiveDirectoryMsiVmAuthentication {
type: typeof AzureActiveDirectoryMsiVmAuthenticationType;
options: {
/**
* If you user want to connect to an Azure app service using a specific client account
* they need to provide `clientId` asscoiate to their created idnetity.
*
* This is optional for retrieve token from azure web app service
*/
clientId?: string;
/**
* A user need to provide `msiEndpoint` for retriving the accesstoken.
*/
msiEndpoint?: string;
};
}


/**
* @param {AzureActiveDirectoryMsiVmAuthentication} authentication
* @throws {TypeError}
*/
export function validateAADMsiVmOptions(authentication: AzureActiveDirectoryMsiVmAuthentication): void {
const { options } = authentication;

if (options.clientId !== undefined && typeof options.clientId !== 'string') {
throw new TypeError('The "config.authentication.options.clientId" property must be of type string.');
}

if (options.msiEndpoint !== undefined && typeof options.msiEndpoint !== 'string') {
throw new TypeError('The "config.authentication.options.msiEndpoint" property must be of type string.');
}

}

/**
* @param {AzureActiveDirectoryMsiVmAuthentication} authentication
* @return {AzureActiveDirectoryMsiVmAuthentication}
*/
export function parseAADMsiVmOptions(authentication: AzureActiveDirectoryMsiVmAuthentication): AzureActiveDirectoryMsiVmAuthentication {
const { options } = authentication;

return {
type: AzureActiveDirectoryMsiVmAuthenticationType,
options: {
clientId: options.clientId,
msiEndpoint: options.msiEndpoint,
},
};
}
59 changes: 59 additions & 0 deletions src/authentication/azure-active-directory-password.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
export const AzureActiveDirectoryPasswordAuthenticationType = 'azure-active-directory-password';

export interface AzureActiveDirectoryPasswordAuthentication {
type: typeof AzureActiveDirectoryPasswordAuthenticationType;

options: {
/**
* A user need to provide `userName` asscoiate to their account.
*/
userName: string;
/**
* A user need to provide `password` asscoiate to their account.
*/
password: string;

/**
* Optional parameter for specific Azure tenant ID
*/
domain: string;
};
}


/**
* @param {AzureActiveDirectoryPasswordAuthentication} authentication
* @throws {TypeError}
*/
export function validateAADPasswordOptions(authentication: AzureActiveDirectoryPasswordAuthentication): void {
const { options } = authentication;

if (options.userName !== undefined && typeof options.userName !== 'string') {
throw new TypeError('The "config.authentication.options.userName" property must be of type string.');
}

if (options.password !== undefined && typeof options.password !== 'string') {
throw new TypeError('The "config.authentication.options.password" property must be of type string.');
}

if (options.domain !== undefined && typeof options.domain !== 'string') {
throw new TypeError('The "config.authentication.options.domain" property must be of type string.');
}
}

/**
* @param {AzureActiveDirectoryPasswordAuthentication} authentication
* @return {AzureActiveDirectoryPasswordAuthentication}
*/
export function parseAADPasswordOptions(authentication: AzureActiveDirectoryPasswordAuthentication): AzureActiveDirectoryPasswordAuthentication {
const { options } = authentication;

return {
type: AzureActiveDirectoryPasswordAuthenticationType,
options: {
userName: options.userName,
password: options.password,
domain: options.domain,
},
};
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
export const AzureActiveDirectoryServicePrincipalSecretType = 'azure-active-directory-service-principal-secret';

export interface AzureActiveDirectoryServicePrincipalSecret {
type: typeof AzureActiveDirectoryServicePrincipalSecretType;
options: {
/**
* Application (`client`) ID from your registered Azure application
*/
clientId: string;
/**
* The created `client secret` for this registered Azure application
*/
clientSecret: string;
/**
* Directory (`tenant`) ID from your registered Azure application
*/
tenantId: string;
};
}


/**
* @param {AzureActiveDirectoryServicePrincipalSecret} authentication
* @throws {TypeError}
*/
export function validateAADServicePrincipalSecretOptions(authentication: AzureActiveDirectoryServicePrincipalSecret): void {
const { options } = authentication;

if (typeof options.clientId !== 'string') {
throw new TypeError('The "config.authentication.options.clientId" property must be of type string.');
}

if (typeof options.clientSecret !== 'string') {
throw new TypeError('The "config.authentication.options.clientSecret" property must be of type string.');
}

if (typeof options.tenantId !== 'string') {
throw new TypeError('The "config.authentication.options.tenantId" property must be of type string.');
}

}

/**
* @param {AzureActiveDirectoryServicePrincipalSecret} authentication
* @return {AzureActiveDirectoryServicePrincipalSecret}
*/
export function parseAADServicePrincipalSecretOptions(authentication: AzureActiveDirectoryServicePrincipalSecret): AzureActiveDirectoryServicePrincipalSecret {
const { options } = authentication;

return {
type: AzureActiveDirectoryServicePrincipalSecretType,
options: {
clientId: options.clientId,
clientSecret: options.clientSecret,
tenantId: options.tenantId,
},
};
}
Loading