add batch, remove graph context, add interactive login token audiences

This commit is contained in:
Ace Eldeib 2018-08-24 15:22:16 -07:00
Родитель fe03b464f5
Коммит 3618e51913
9 изменённых файлов: 60 добавлений и 41 удалений

22
dist/lib/credentials/tokenCredentialsBase.js поставляемый
Просмотреть файл

@ -26,25 +26,23 @@ class TokenCredentialsBase {
if (!Boolean(domain) || typeof domain.valueOf() !== "string") {
throw new Error("domain must be a non empty string.");
}
if (this.tokenAudience === "graph") {
this.isGraphContext = true;
if (this.domain.toLowerCase() === "common") {
throw new Error(`${"If the tokenAudience is specified as \"graph\" then \"domain\" cannot be defaulted to \"commmon\" tenant.\
It must be the actual tenant (preferrably a string in a guid format)."}`);
}
}
else {
this.isGraphContext = false;
if (this.tokenAudience === "graph" && this.domain.toLowerCase() === "common") {
throw new Error(`${"If the tokenAudience is specified as \"graph\" then \"domain\" cannot be defaulted to \"commmon\" tenant.\
It must be the actual tenant (preferrably a string in a guid format)."}`);
}
const authorityUrl = this.environment.activeDirectoryEndpointUrl + this.domain;
this.authContext = new adal.AuthenticationContext(authorityUrl, this.environment.validateAuthority, this.tokenCache);
}
getActiveDirectoryResourceId() {
let resource = this.isGraphContext
? this.environment.activeDirectoryGraphResourceId
: this.environment.activeDirectoryResourceId;
let resource = this.environment.activeDirectoryResourceId;
if (this.tokenAudience) {
resource = this.tokenAudience;
if (this.tokenAudience === "graph") {
resource = this.environment.activeDirectoryGraphResourceId;
}
else if (this.tokenAudience === "graph") {
resource = this.environment.batchResourceId;
}
}
return resource;
}

Просмотреть файл

@ -1 +1 @@
{"version":3,"file":"tokenCredentialsBase.js","sourceRoot":"","sources":["../../../lib/credentials/tokenCredentialsBase.ts"],"names":[],"mappings":";AAAA,4DAA4D;AAC5D,+FAA+F;;;;;;;;;;AAE/F,2CAAuE;AACvE,yDAAqD;AAErD,MAAM,IAAI,GAAG,OAAO,CAAC,WAAW,CAAC,CAAC;AAQlC;IAIE,YACkB,QAAgB,EACzB,MAAc,EACL,aAA6B,EAC7B,c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CAAC;aAC5D;iBAAM,IAAI,IAAI,CAAC,aAAa,KAAK,OAAO,EAAE;gBACzC,QAAQ,GAAG,IAAI,CAAC,WAAW,CAAC,eAAe,CAAC;aAC7C;SACF;QACD,OAAO,QAAQ,CAAC;IAClB,CAAC;IAES,iBAAiB,CAAC,QAAiB;QAC3C,MAAM,IAAI,GAAG,IAAI,CAAC;QAClB,MAAM,QAAQ,GAAG,IAAI,CAAC,4BAA4B,EAAE,CAAC;QAErD,OAAO,IAAI,OAAO,CAAgB,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;YACpD,IAAI,CAAC,WAAW,CAAC,YAAY,CAAC,QAAQ,EAAE,QAAQ,EAAE,IAAI,CAAC,QAAQ,EAAE,CAAC,KAAY,EAAE,aAA4B,EAAE,EAAE;gBAC9G,IAAI,KAAK,EAAE;oBACT,OAAO,MAAM,CAAC,KAAK,CAAC,CAAC;iBACtB;gBACD,OAAO,OAAO,CAAC,aAAa,CAAC,CAAC;YAChC,CAAC,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;IACL,CAAC;IAUD;;;;;;OAMG;IACU,WAAW,CAAC,WAAwB;;YAC/C,MAAM,aAAa,GAAG,MAAM,IAAI,CAAC,QAAQ,EAAE,CAAC;YAC5C,WAAW,CAAC,OAAO,CAAC,GAAG,CAAC,sBAAe,CAAC,eAAe,CAAC,aAAa,EAAE,GAAG,aAAa,CAAC,SAAS,IAAI,aAAa,CAAC,WAAW,EAAE,CAAC,CAAC;YAClI,OAAO,OAAO,CAAC,OAAO,CAAC,WAAW,CAAC,CAAC;QACtC,CAAC;KAAA;CACF;AA1ED,oDA0EC"}

21
dist/lib/login.js поставляемый
Просмотреть файл

@ -319,6 +319,9 @@ function withInteractiveWithAuthResponse(options) {
if (!options.language) {
options.language = authConstants_1.AuthConstants.DEFAULT_LANGUAGE;
}
if (!options.tokenAudience) {
options.tokenAudience = options.environment.activeDirectoryResourceId;
}
const interactiveOptions = {};
interactiveOptions.tokenAudience = options.tokenAudience;
interactiveOptions.environment = options.environment;
@ -332,10 +335,17 @@ function withInteractiveWithAuthResponse(options) {
interactiveOptions.context = authContext;
let userCodeResponse;
let creds;
const getUserCode = new Promise((resolve, reject) => {
return authContext.acquireUserCode(interactiveOptions.environment.activeDirectoryResourceId, interactiveOptions.clientId, interactiveOptions.language, (err, userCodeRes) => {
function tryAcquireToken(interactiveOptions, resolve, reject) {
authContext.acquireUserCode(interactiveOptions.tokenAudience, interactiveOptions.clientId, interactiveOptions.language, (err, userCodeRes) => {
if (err) {
return reject(err);
if (err.error === "authorization_pending") {
setTimeout(() => {
tryAcquireToken(interactiveOptions, resolve, reject);
}, 1000);
}
else {
return reject(err);
}
}
userCodeResponse = userCodeRes;
if (interactiveOptions.userCodeResponseLogger) {
@ -346,6 +356,9 @@ function withInteractiveWithAuthResponse(options) {
}
return resolve(userCodeResponse);
});
}
const getUserCode = new Promise((resolve, reject) => {
return tryAcquireToken(interactiveOptions, resolve, reject);
});
function getSubscriptions(creds, tenants) {
if (interactiveOptions.tokenAudience && interactiveOptions.tokenAudience === interactiveOptions.environment.activeDirectoryResourceId) {
@ -355,7 +368,7 @@ function withInteractiveWithAuthResponse(options) {
}
return getUserCode.then(() => {
return new Promise((resolve, reject) => {
return authContext.acquireTokenWithDeviceCode(interactiveOptions.environment.activeDirectoryResourceId, interactiveOptions.clientId, userCodeResponse, (error, tokenResponse) => {
return authContext.acquireTokenWithDeviceCode(interactiveOptions.tokenAudience, interactiveOptions.clientId, userCodeResponse, (error, tokenResponse) => {
if (error) {
return reject(error);
}

2
dist/lib/login.js.map поставляемый

Различия файлов скрыты, потому что одна или несколько строк слишком длинны

Просмотреть файл

@ -13,7 +13,6 @@ export interface TokenResponse {
}
export abstract class TokenCredentialsBase {
protected readonly isGraphContext: boolean;
protected readonly authContext: any;
public constructor(
@ -31,15 +30,9 @@ export abstract class TokenCredentialsBase {
throw new Error("domain must be a non empty string.");
}
if (this.tokenAudience === "graph") {
this.isGraphContext = true;
if (this.domain.toLowerCase() === "common") {
throw new Error(`${"If the tokenAudience is specified as \"graph\" then \"domain\" cannot be defaulted to \"commmon\" tenant.\
It must be the actual tenant (preferrably a string in a guid format)."}`);
}
} else {
this.isGraphContext = false;
if (this.tokenAudience === "graph" && this.domain.toLowerCase() === "common") {
throw new Error(`${"If the tokenAudience is specified as \"graph\" then \"domain\" cannot be defaulted to \"commmon\" tenant.\
It must be the actual tenant (preferrably a string in a guid format)."}`);
}
const authorityUrl = this.environment.activeDirectoryEndpointUrl + this.domain;
@ -47,14 +40,15 @@ export abstract class TokenCredentialsBase {
}
protected getActiveDirectoryResourceId(): string {
let resource = this.isGraphContext
? this.environment.activeDirectoryGraphResourceId
: this.environment.activeDirectoryResourceId;
let resource = this.environment.activeDirectoryResourceId;
if (this.tokenAudience) {
resource = this.tokenAudience;
resource = this.tokenAudience;
if (this.tokenAudience === "graph") {
resource = this.environment.activeDirectoryGraphResourceId;
} else if (this.tokenAudience === "graph") {
resource = this.environment.batchResourceId;
}
}
return resource;
}

Просмотреть файл

@ -413,6 +413,10 @@ export async function withInteractiveWithAuthResponse(options?: InteractiveLogin
if (!options.language) {
options.language = AuthConstants.DEFAULT_LANGUAGE;
}
if (!options.tokenAudience) {
options.tokenAudience = options.environment.activeDirectoryResourceId;
}
const interactiveOptions: any = {};
interactiveOptions.tokenAudience = options.tokenAudience;
interactiveOptions.environment = options.environment;
@ -426,10 +430,17 @@ export async function withInteractiveWithAuthResponse(options?: InteractiveLogin
interactiveOptions.context = authContext;
let userCodeResponse: any;
let creds: DeviceTokenCredentials;
const getUserCode = new Promise<any>((resolve, reject) => {
return authContext.acquireUserCode(interactiveOptions.environment.activeDirectoryResourceId, interactiveOptions.clientId, interactiveOptions.language, (err: Error, userCodeRes: any) => {
function tryAcquireToken(interactiveOptions: InteractiveLoginOptions, resolve: any, reject: any) {
authContext.acquireUserCode(interactiveOptions.tokenAudience, interactiveOptions.clientId, interactiveOptions.language, (err: any, userCodeRes: any) => {
if (err) {
return reject(err);
if (err.error === "authorization_pending") {
setTimeout(() => {
tryAcquireToken(interactiveOptions, resolve, reject);
}, 1000);
} else {
return reject(err);
}
}
userCodeResponse = userCodeRes;
if (interactiveOptions.userCodeResponseLogger) {
@ -439,6 +450,10 @@ export async function withInteractiveWithAuthResponse(options?: InteractiveLogin
}
return resolve(userCodeResponse);
});
}
const getUserCode = new Promise<any>((resolve, reject) => {
return tryAcquireToken(interactiveOptions, resolve, reject);
});
function getSubscriptions(creds: DeviceTokenCredentials, tenants: string[]): Promise<LinkedSubscription[]> {
@ -450,7 +465,7 @@ export async function withInteractiveWithAuthResponse(options?: InteractiveLogin
return getUserCode.then(() => {
return new Promise<DeviceTokenCredentials>((resolve, reject) => {
return authContext.acquireTokenWithDeviceCode(interactiveOptions.environment.activeDirectoryResourceId, interactiveOptions.clientId, userCodeResponse, (error: Error, tokenResponse: any) => {
return authContext.acquireTokenWithDeviceCode(interactiveOptions.tokenAudience, interactiveOptions.clientId, userCodeResponse, (error: Error, tokenResponse: any) => {
if (error) {
return reject(error);
}

Просмотреть файл

@ -9,4 +9,4 @@ export const AuthConstants = {
"AZURE_AUTH_LOCATION": "AZURE_AUTH_LOCATION"
};
export type TokenAudience = string | "graph";
export type TokenAudience = "graph" | "batch" | string | undefined;

Просмотреть файл

@ -28,7 +28,6 @@ export declare abstract class TokenCredentialsBase {
validateAuthority: boolean;
};
tokenCache: any;
protected readonly isGraphContext: boolean;
protected readonly authContext: any;
constructor(clientId: string, domain: string, tokenAudience?: string | undefined, environment?: {
name: string;

2
typings/lib/util/authConstants.d.ts поставляемый
Просмотреть файл

@ -5,4 +5,4 @@ export declare const AuthConstants: {
"DEFAULT_LANGUAGE": string;
"AZURE_AUTH_LOCATION": string;
};
export declare type TokenAudience = string | "graph";
export declare type TokenAudience = "graph" | "batch" | string | undefined;