-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[core-http] Remove ServiceClientCredentials from ServiceClient API (#…
…4367) * Remove ServiceClientCredentials from ServiceClient API * Remove additional check added to isTokenCredential This rolls back the change made in 771614e because it will prevent forward-compatibility in `ms-rest-nodeauth` and `ms-rest-browserauth` credentials. * Improve RawTokenCredential comment * Improve credential detection logic in ServiceClient * Add isTokenCredential heuristic to identify TokenClientCredentials * Simplify ServiceClient constructor logic around credentials * Move RawTokenCredential from core-http to core-arm * Delete TokenCredentials, update samples to use RawTokenCredential * Rename RawTokenCredential to SimpleTokenCredential
- Loading branch information
1 parent
e12f8e5
commit 8e3db7c
Showing
27 changed files
with
143 additions
and
196 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
import { TokenCredential, GetTokenOptions, AccessToken } from "./tokenCredential"; | ||
|
||
/** | ||
* A TokenCredential that always returns the given token. This class can be | ||
* used when the access token is already known or can be retrieved from an | ||
* outside source. | ||
*/ | ||
export class SimpleTokenCredential implements TokenCredential { | ||
/** | ||
* The raw token string. Can be changed when the token needs to be updated. | ||
*/ | ||
public token: string; | ||
|
||
/** | ||
* The Date at which the token expires. Can be changed to update the expiration time. | ||
*/ | ||
public expiresOn: Date; | ||
|
||
/** | ||
* Creates an instance of TokenCredential. | ||
* @param {string} token | ||
*/ | ||
constructor(token: string, expiresOn?: Date) { | ||
this.token = token; | ||
this.expiresOn = expiresOn ? expiresOn : new Date(Date.now() + 60*60*1000); | ||
} | ||
|
||
/** | ||
* Retrieves the token stored in this RawTokenCredential. | ||
* | ||
* @param _scopes Ignored since token is already known. | ||
* @param _options Ignored since token is already known. | ||
* @returns {AccessToken} The access token details. | ||
*/ | ||
async getToken(_scopes: string | string[], _options?: GetTokenOptions): Promise<AccessToken | null> { | ||
return { | ||
token: this.token, | ||
expiresOnTimestamp: this.expiresOn.getTime() | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.