forked from Azure/azure-sdk-for-js
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
@azure/communication-common Azure Core 2.0 Migration (Azure#20337)
* migrated clientArguments, removed circular deps * removed the dependency on @azure/core-http * policy converted to core rest pipeline * removed the old policy, bumped major version * added a changelog entry * added test * updated pnpm file
- Loading branch information
1 parent
c2ae230
commit a595cb2
Showing
23 changed files
with
471 additions
and
443 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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
5 changes: 3 additions & 2 deletions
5
sdk/communication/communication-common/src/autoRefreshTokenCredential.ts
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
68 changes: 68 additions & 0 deletions
68
sdk/communication/communication-common/src/azureCommunicationTokenCredential.ts
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,68 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT license. | ||
|
||
import { | ||
AutoRefreshTokenCredential, | ||
CommunicationTokenRefreshOptions, | ||
} from "./autoRefreshTokenCredential"; | ||
import { | ||
CommunicationGetTokenOptions, | ||
CommunicationTokenCredential, | ||
TokenCredential, | ||
} from "./communicationTokenCredential"; | ||
import { AccessToken } from "@azure/core-auth"; | ||
import { StaticTokenCredential } from "./staticTokenCredential"; | ||
import { parseToken } from "./tokenParser"; | ||
|
||
/** | ||
* The CommunicationTokenCredential implementation with support for proactive token refresh. | ||
*/ | ||
|
||
export class AzureCommunicationTokenCredential implements CommunicationTokenCredential { | ||
private readonly tokenCredential: TokenCredential; | ||
private disposed = false; | ||
|
||
/** | ||
* Creates an instance of CommunicationTokenCredential with a static token and no proactive refreshing. | ||
* @param token - A user access token issued by Communication Services. | ||
*/ | ||
constructor(token: string); | ||
/** | ||
* Creates an instance of CommunicationTokenCredential with a lambda to get a token and options | ||
* to configure proactive refreshing. | ||
* @param refreshOptions - Options to configure refresh and opt-in to proactive refreshing. | ||
*/ | ||
constructor(refreshOptions: CommunicationTokenRefreshOptions); | ||
constructor(tokenOrRefreshOptions: string | CommunicationTokenRefreshOptions) { | ||
if (typeof tokenOrRefreshOptions === "string") { | ||
this.tokenCredential = new StaticTokenCredential(parseToken(tokenOrRefreshOptions)); | ||
} else { | ||
this.tokenCredential = new AutoRefreshTokenCredential(tokenOrRefreshOptions); | ||
} | ||
} | ||
|
||
/** | ||
* Gets an `AccessToken` for the user. Throws if already disposed. | ||
* @param abortSignal - An implementation of `AbortSignalLike` to cancel the operation. | ||
*/ | ||
public async getToken(options?: CommunicationGetTokenOptions): Promise<AccessToken> { | ||
this.throwIfDisposed(); | ||
const token = await this.tokenCredential.getToken(options); | ||
this.throwIfDisposed(); | ||
return token; | ||
} | ||
|
||
/** | ||
* Disposes the CommunicationTokenCredential and cancels any internal auto-refresh operation. | ||
*/ | ||
public dispose(): void { | ||
this.disposed = true; | ||
this.tokenCredential.dispose(); | ||
} | ||
|
||
private throwIfDisposed(): void { | ||
if (this.disposed) { | ||
throw new Error("User credential is disposed"); | ||
} | ||
} | ||
} |
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
13 changes: 6 additions & 7 deletions
13
sdk/communication/communication-common/src/credential/clientArguments.ts
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
Oops, something went wrong.