/// <summary> /// Authenticate using know auth token, renew token and expiration time /// </summary> /// <param name="authToken"></param> /// <param name="authRenewToken"></param> /// <param name="authTokenExpiration"></param> /// <returns>True if authenticated</returns> public async Task<bool> Authentication(string authToken, string authRenewToken, DateTime authTokenExpiration) { Token = new AuthToken { expires_in = 0, createdTime = authTokenExpiration, access_token = authToken, refresh_token = authRenewToken, token_type = "bearer" }; await UpdateToken().ConfigureAwait(false); return Token != null; }
private async Task UpdateToken() { updatingToken = true; try { var form = new Dictionary<string, string> { { "grant_type", "refresh_token" }, { "refresh_token", token.refresh_token }, { "client_id", clientId }, { "client_secret", clientSecret } }; var newtoken = await http.PostForm<AuthToken>(TokenUrl, form).ConfigureAwait(false); if (newtoken != null) { token = newtoken; CallOnTokenUpdate(token.access_token, token.refresh_token, DateTime.UtcNow.AddSeconds(token.expires_in)); } } finally { updatingToken = false; } }
/// <inheritdoc/> public async Task<bool> AuthenticationByCode(string code, string redirectUrl) { var form = new Dictionary<string, string> { { "grant_type", "authorization_code" }, { "code", code }, { "client_id", clientId }, { "client_secret", clientSecret }, { "redirect_uri", redirectUrl } }; token = await http.PostForm<AuthToken>(TokenUrl, form).ConfigureAwait(false); if (token != null) { CallOnTokenUpdate(token.access_token, token.refresh_token, DateTime.UtcNow.AddSeconds(token.expires_in)); await Account.GetEndpoint().ConfigureAwait(false); return true; } return false; }