/// <summary> /// Generate the request credentials parameters from an AuthenticationTokenProvider /// If the url does not contain the expected input or the token provider cannot find /// the authentication token, this will return an error. /// </summary> /// <exception cref="ArgumentException">When callback url is not properly formatted</exception> public static async Task <IRequestCredentialsParameters> FromCallbackUrlAsync(string callbackUrl, IAuthenticationRequestStore authenticationRequestStore) { var tokenId = authenticationRequestStore.ExtractAuthenticationRequestIdFromCallbackUrl(callbackUrl); var authToken = await authenticationRequestStore.GetAuthenticationRequestFromIdAsync(tokenId).ConfigureAwait(false); if (authToken == null) { throw new Exception("Could not retrieve the authentication token"); } await authenticationRequestStore.RemoveAuthenticationTokenAsync(tokenId).ConfigureAwait(false); var oAuthVerifier = callbackUrl.GetURLParameter("oauth_verifier"); if (oAuthVerifier == null) { throw new ArgumentException($"oauth_verifier query parameter not found, this is required to authenticate the user", nameof(callbackUrl)); } return(new RequestCredentialsParameters(oAuthVerifier, authToken)); }