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); }
public static Task <string> GetAuthUrlAsync(ResumptionCookie resumptionCookie, string resourceId) { // https://start.exactonline.nl/api/oauth2/auth?client_id=01b85808-0248-47a8-9f25-08acd900f788&redirect_uri=http://www.mstack.nl&response_type=code&force_login=0&state=test var settings = AuthenticationSettings.GetFromAppSettings(); string stateParameter = AuthUtilities.EncodeResumptionCookie(resumptionCookie); NameValueCollection queryParams = new NameValueCollection(); queryParams.Add("client_id", settings.ClientId); queryParams.Add("redirect_uri", settings.RedirectUrl); queryParams.Add("response_type", "code"); queryParams.Add("force_login", "0"); queryParams.Add("state", stateParameter); string queryString = AuthUtilities.ToQueryString(queryParams); string result = "https://start.exactonline.nl/api/oauth2/auth" + queryString; return(Task.FromResult(result)); }