@microsoft/kiota-authentication-azure
Advanced tools
Comparing version 1.0.0-preview.10 to 1.0.0-preview.11
@@ -25,2 +25,5 @@ import { GetTokenOptions, TokenCredential } from "@azure/core-auth"; | ||
private getAuthorizationTokenInternal; | ||
private getSchemeAndHostFromUrl; | ||
private getSchemeFromLocation; | ||
private getHostFromLocation; | ||
/** | ||
@@ -27,0 +30,0 @@ * @inheritdoc |
@@ -17,12 +17,3 @@ "use strict"; | ||
*/ | ||
constructor(credentials, scopes = [ | ||
"https://graph.microsoft.com/.default", | ||
], options, allowedHosts = new Set([ | ||
"graph.microsoft.com", | ||
"graph.microsoft.us", | ||
"dod-graph.microsoft.us", | ||
"graph.microsoft.de", | ||
"microsoftgraph.chinacloudapi.cn", | ||
"canary.graph.microsoft.com", | ||
]), observabilityOptions = new observabilityOptions_1.ObservabilityOptionsImpl()) { | ||
constructor(credentials, scopes = [], options, allowedHosts = new Set(), observabilityOptions = new observabilityOptions_1.ObservabilityOptionsImpl()) { | ||
this.credentials = credentials; | ||
@@ -66,2 +57,6 @@ this.scopes = scopes; | ||
} | ||
if (this.scopes.length === 0) { | ||
const [scheme, host] = this.getSchemeAndHostFromUrl(url); | ||
this.scopes.push(`${scheme}://${host}/.default`); | ||
} | ||
span === null || span === void 0 ? void 0 : span.setAttribute("com.microsoft.kiota.authentication.scopes", this.scopes.join(",")); | ||
@@ -71,2 +66,32 @@ const result = yield this.credentials.getToken(this.scopes, localOptions); | ||
}); | ||
this.getSchemeAndHostFromUrl = (url) => { | ||
const urlParts = url.split("://"); | ||
if (urlParts.length === 0) { | ||
// relative url | ||
return [this.getSchemeFromLocation(), this.getHostFromLocation()]; | ||
} | ||
else if (urlParts.length === 1) { | ||
// protocol relative url | ||
return [this.getSchemeFromLocation(), urlParts[0].split("/")[0]]; | ||
} | ||
else if (urlParts.length >= 2) { | ||
// absolute url | ||
return [urlParts[0], urlParts[1].split("/")[0]]; | ||
} | ||
else { | ||
throw new Error("invalid url"); | ||
} | ||
}; | ||
this.getSchemeFromLocation = () => { | ||
if (window && window.location && window.location.protocol) { | ||
return window.location.protocol.replace(":", ""); | ||
} | ||
return ""; | ||
}; | ||
this.getHostFromLocation = () => { | ||
if (window && window.location && window.location.host) { | ||
return window.location.host; | ||
} | ||
return ""; | ||
}; | ||
/** | ||
@@ -79,4 +104,4 @@ * @inheritdoc | ||
} | ||
if (!scopes || scopes.length === 0) { | ||
throw new Error("scopes cannot be null or empty"); | ||
if (!scopes) { | ||
throw new Error("scopes cannot be null"); | ||
} | ||
@@ -83,0 +108,0 @@ if (!observabilityOptions) { |
@@ -25,2 +25,5 @@ import { GetTokenOptions, TokenCredential } from "@azure/core-auth"; | ||
private getAuthorizationTokenInternal; | ||
private getSchemeAndHostFromUrl; | ||
private getSchemeFromLocation; | ||
private getHostFromLocation; | ||
/** | ||
@@ -27,0 +30,0 @@ * @inheritdoc |
@@ -13,12 +13,3 @@ import { AllowedHostsValidator, validateProtocol, } from "@microsoft/kiota-abstractions"; | ||
*/ | ||
constructor(credentials, scopes = [ | ||
"https://graph.microsoft.com/.default", | ||
], options, allowedHosts = new Set([ | ||
"graph.microsoft.com", | ||
"graph.microsoft.us", | ||
"dod-graph.microsoft.us", | ||
"graph.microsoft.de", | ||
"microsoftgraph.chinacloudapi.cn", | ||
"canary.graph.microsoft.com", | ||
]), observabilityOptions = new ObservabilityOptionsImpl()) { | ||
constructor(credentials, scopes = [], options, allowedHosts = new Set(), observabilityOptions = new ObservabilityOptionsImpl()) { | ||
this.credentials = credentials; | ||
@@ -62,2 +53,6 @@ this.scopes = scopes; | ||
} | ||
if (this.scopes.length === 0) { | ||
const [scheme, host] = this.getSchemeAndHostFromUrl(url); | ||
this.scopes.push(`${scheme}://${host}/.default`); | ||
} | ||
span === null || span === void 0 ? void 0 : span.setAttribute("com.microsoft.kiota.authentication.scopes", this.scopes.join(",")); | ||
@@ -67,2 +62,32 @@ const result = await this.credentials.getToken(this.scopes, localOptions); | ||
}; | ||
this.getSchemeAndHostFromUrl = (url) => { | ||
const urlParts = url.split("://"); | ||
if (urlParts.length === 0) { | ||
// relative url | ||
return [this.getSchemeFromLocation(), this.getHostFromLocation()]; | ||
} | ||
else if (urlParts.length === 1) { | ||
// protocol relative url | ||
return [this.getSchemeFromLocation(), urlParts[0].split("/")[0]]; | ||
} | ||
else if (urlParts.length >= 2) { | ||
// absolute url | ||
return [urlParts[0], urlParts[1].split("/")[0]]; | ||
} | ||
else { | ||
throw new Error("invalid url"); | ||
} | ||
}; | ||
this.getSchemeFromLocation = () => { | ||
if (window && window.location && window.location.protocol) { | ||
return window.location.protocol.replace(":", ""); | ||
} | ||
return ""; | ||
}; | ||
this.getHostFromLocation = () => { | ||
if (window && window.location && window.location.host) { | ||
return window.location.host; | ||
} | ||
return ""; | ||
}; | ||
/** | ||
@@ -75,4 +100,4 @@ * @inheritdoc | ||
} | ||
if (!scopes || scopes.length === 0) { | ||
throw new Error("scopes cannot be null or empty"); | ||
if (!scopes) { | ||
throw new Error("scopes cannot be null"); | ||
} | ||
@@ -79,0 +104,0 @@ if (!observabilityOptions) { |
{ | ||
"name": "@microsoft/kiota-authentication-azure", | ||
"version": "1.0.0-preview.10", | ||
"version": "1.0.0-preview.11", | ||
"description": "Authentication provider for Kiota using Azure Identity", | ||
@@ -33,3 +33,3 @@ "main": "dist/cjs/src/index.js", | ||
"@azure/core-auth": "^1.3.2", | ||
"@microsoft/kiota-abstractions": "^1.0.0-preview.12", | ||
"@microsoft/kiota-abstractions": "^1.0.0-preview.13", | ||
"@opentelemetry/api": "^1.2.0", | ||
@@ -41,3 +41,3 @@ "tslib": "^2.3.1" | ||
}, | ||
"gitHead": "c4f4973ba1ed983605a6474bf3fff49989728a10" | ||
"gitHead": "19b0c8c496390930ef0229fe0691d3487db34342" | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
126675
392