Ejemplo n.º 1
0
        public async Task CommunicationUserCredential_DecodesToken(string token, long expectedExpiryUnixTimeSeconds)
        {
            using var userCredential = new CommunicationUserCredential(token);
            AccessToken accessToken = await userCredential.GetTokenAsync();

            Assert.AreEqual(token, accessToken.Token);
            Assert.AreEqual(expectedExpiryUnixTimeSeconds, accessToken.ExpiresOn.ToUnixTimeSeconds());
        }
Ejemplo n.º 2
0
 public async Task CommunicationUserCredential_CreateRefreshableWithoutInitialToken()
 {
     #region Snippet:CommunicationUserCredential_CreateRefreshableWithoutInitialToken
     using var userCredential = new CommunicationUserCredential(
               refreshProactively: true, // Indicates if the token should be proactively refreshed in the background or only on-demand
               tokenRefresher: cancellationToken => FetchTokenForUserFromMyServer("*****@*****.**", cancellationToken),
               asyncTokenRefresher: cancellationToken => FetchTokenForUserFromMyServerAsync("*****@*****.**", cancellationToken));
     #endregion
     await userCredential.GetTokenAsync();
 }
Ejemplo n.º 3
0
        public async Task CommunicationUserCredential_CreateStaticToken()
        {
            var token = ExpiredToken;

            #region Snippet:CommunicationUserCredential_CreateWithStaticToken
            //@@string token = Environment.GetEnvironmentVariable("COMMUNICATION_SERVICES_USER_TOKEN");
            using var userCredential = new CommunicationUserCredential(token);
            #endregion
            await userCredential.GetTokenAsync();
        }
Ejemplo n.º 4
0
        public async Task CommunicationUserCredential_CreateRefreshableWithInitialToken()
        {
            var initialToken = ExpiredToken;

            #region Snippet:CommunicationUserCredential_CreateRefreshableWithInitialToken
            //@@string initialToken = Environment.GetEnvironmentVariable("COMMUNICATION_SERVICES_USER_TOKEN");
            using var userCredential = new CommunicationUserCredential(
                      refreshProactively: true, // Indicates if the token should be proactively refreshed in the background or only on-demand
                      tokenRefresher: cancellationToken => FetchTokenForUserFromMyServer("*****@*****.**", cancellationToken),
                      asyncTokenRefresher: cancellationToken => FetchTokenForUserFromMyServerAsync("*****@*****.**", cancellationToken),
                      initialToken);
            #endregion
            await userCredential.GetTokenAsync();
        }