protected virtual async Task<OAuthAccount> GetAccountFromAuthCode(WebAuthenticator authenticator, string identifier)
{
var postData = await authenticator.GetTokenPostData(ClientSecret);
if (string.IsNullOrWhiteSpace(TokenUrl))
throw new Exception("Invalid TokenURL");
var message = new HttpRequestMessage (HttpMethod.Post, TokenUrl) {
Content = new FormUrlEncodedContent (postData),
Headers = {
{"Accept","application/json"}
}
};
var reply = await Client.SendAsync (message);
var resp = await reply.Content.ReadAsStringAsync();
var result = Deserialize<OauthResponse>(resp);
if (!string.IsNullOrEmpty(result?.Error))
throw new Exception(result.ErrorDescription);
var account = new OAuthAccount () {
ExpiresIn = result.ExpiresIn,
Created = DateTime.UtcNow,
RefreshToken = result.RefreshToken,
Scope = authenticator.Scope?.ToArray (),
TokenType = result.TokenType,
Token = result.AccessToken,
ClientId = ClientId,
Identifier = identifier,
Cookies = authenticator.Cookies,
};
return account;
}