Skip to content

Commit

Permalink
AzCli authentication via @azure/identity (#144)
Browse files Browse the repository at this point in the history
  • Loading branch information
amshalev authored Aug 8, 2021
1 parent 5034886 commit a4b6805
Show file tree
Hide file tree
Showing 5 changed files with 2,577 additions and 604 deletions.
132 changes: 3 additions & 129 deletions azure-kusto-data/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions azure-kusto-data/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "azure-kusto-data",
"version": "2.2.1",
"version": "2.2.2",
"description": "Azure Data Explorer Query SDK",
"main": "index.js",
"types": "index.d.ts",
Expand Down Expand Up @@ -34,7 +34,6 @@
"homepage": "https://github.com/Azure/azure-kusto-node/blob/master/azure-kusto-data/README.md",
"dependencies": {
"@azure/identity": "^1.3.0",
"@azure/ms-rest-nodeauth": "^3.0.10",
"@azure/msal-node": "^1.1.0",
"@types/mocha": "^8.2.0",
"@types/node": "^14.14.13",
Expand Down
14 changes: 9 additions & 5 deletions azure-kusto-data/source/tokenProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
// Licensed under the MIT License.
import { AuthenticationResult, PublicClientApplication, ConfidentialClientApplication } from "@azure/msal-node";
import { DeviceCodeResponse } from "@azure/msal-common";
import { AzureCliCredentials } from "@azure/ms-rest-nodeauth";
import { ManagedIdentityCredential } from "@azure/identity";
import { ManagedIdentityCredential, AzureCliCredential} from "@azure/identity";
import { CloudSettings, CloudInfo } from "./cloudSettings"

export declare type TokenResponse = {
Expand Down Expand Up @@ -93,17 +92,22 @@ export class MsiTokenProvider extends TokenProviderBase {
* AzCli Token Provider obtains a refresh token from the AzCli cache and uses it to authenticate with MSAL
*/
export class AzCliTokenProvider extends TokenProviderBase {
azureCliCredentials!: AzureCliCredentials;
azureCliCredentials!: AzureCliCredential;

constructor(kustoUri: string) {
super(kustoUri);
}

async acquireToken(): Promise<TokenResponse> {
if (this.azureCliCredentials == null) {
this.azureCliCredentials = await AzureCliCredentials.create({ resource: this.kustoUri });
this.azureCliCredentials = new AzureCliCredential();
}
return this.azureCliCredentials.getToken();
const response = await this.azureCliCredentials.getToken(this.scopes);

if(response){
return { tokenType: BEARER_TYPE, accessToken: response.token };
}
throw new Error(`"Failed to obtain AzCli token for '${this.kustoUri}'`)
}
}

Expand Down
Loading

0 comments on commit a4b6805

Please sign in to comment.