示例#1
0
        public static async Task <string> GetExactOnlineAccessToken(this IBotContext context)
        {
            AuthenticationSettings authenticationSettings = AuthenticationSettings.GetFromAppSettings();
            AuthenticationResult   authenticationResult;

            string authResultKey = AuthenticationConstants.AuthDialogId_ExactOnline + '_' + AuthenticationConstants.AuthResultKey;

            if (context.UserData.TryGetValue(authResultKey, out authenticationResult))
            {
                try
                {
                    var tokenCache = TokenCacheFactory.SetTokenCache(authenticationResult.TokenCache);

                    var result = await ExactOnlineHelper.GetToken(authenticationResult.UserUniqueId);

                    authenticationResult.AccessToken       = result.AccessToken;
                    authenticationResult.ExpiresOnUtcTicks = result.ExpiresOnUtcTicks;
                    authenticationResult.TokenCache        = tokenCache.Serialize();
                    context.StoreAuthResult(authenticationResult);
                }
                catch (Exception ex)
                {
                    Trace.TraceError("Failed to renew token: " + ex.Message);
                    await context.PostAsync("Your credentials expired and could not be renewed automatically!");

                    await context.Logout(authenticationSettings);

                    return(null);
                }
                return(authenticationResult.AccessToken);
            }

            return(null);
        }
示例#2
0
 public override Task <string> GetAuthUrl(ResumptionCookie resumptionCookie)
 {
     return(ExactOnlineHelper.GetAuthUrlAsync(resumptionCookie, this.resourceId));
 }
 protected override Task <Auth.AuthenticationResult> GetTokenByAuthCodeAsync(NameValueCollection parameters)
 {
     return(ExactOnlineHelper.GetTokenByAuthCode(parameters));
 }
 public AuthCallbackHandler(int maxWriteAttempts) : base(maxWriteAttempts)
 {
     Client = ExactOnlineHelper.GetClient();
 }