-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Communcation] - Common - Renaming CommunicationUserCredential to Com…
…municationTokenCredential (#17989) * Renaming CommunicationUserCredential to CommunicationTokenCredential * Fixing build * update read me * Remove unneeded export * Addressing PR comments Co-authored-by: Minnie Liu <peiliu@microsoft.com>
- Loading branch information
Showing
11 changed files
with
378 additions
and
423 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
42 changes: 42 additions & 0 deletions
42
.../java/com/azure/communication/chat/implementation/CommunicationBearerTokenCredential.java
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,42 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
package com.azure.communication.chat.implementation; | ||
|
||
import java.util.concurrent.ExecutionException; | ||
|
||
import com.azure.communication.common.CommunicationTokenCredential; | ||
import com.azure.core.credential.AccessToken; | ||
import com.azure.core.credential.TokenCredential; | ||
import com.azure.core.credential.TokenRequestContext; | ||
|
||
import reactor.core.publisher.Mono; | ||
|
||
/** | ||
* This class serves as a CommunicationTokenCredential wrapper that | ||
* allows using BearerAuthenticationPolicy in different clients | ||
*/ | ||
public class CommunicationBearerTokenCredential implements TokenCredential { | ||
private final CommunicationTokenCredential credential; | ||
|
||
/** | ||
* Creates a CommunicationTokenCredential | ||
* | ||
* @param communicationTokenCredential The {@link CommunicationTokenCredential} to use | ||
* in the BearerAuthenticationPolicy. | ||
*/ | ||
public CommunicationBearerTokenCredential(CommunicationTokenCredential communicationTokenCredential) { | ||
credential = communicationTokenCredential; | ||
} | ||
|
||
@Override | ||
public Mono<AccessToken> getToken(TokenRequestContext request) { | ||
try { | ||
return Mono.just(credential.getToken().get()); | ||
} catch (InterruptedException ex) { | ||
return Mono.error(ex); | ||
} catch (ExecutionException ex) { | ||
return Mono.error(ex); | ||
} | ||
} | ||
} |
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
Oops, something went wrong.