I'm trying to authenticate my client via Graph API, but with the need of a RefreshToken, which I can store, so the SDKs vor e.g. UWP are not useful.
So I build the Login-Link with:
string url = $"https://login.microsoftonline.com/consumers/oauth2/v2.0/authorize" +
$"?client_id={ClientId}&response_type=code" +
$"&redirect_url={WebUtility.UrlEncode(RedirectUrl)}" +
$"&scope={WebUtility.UrlEncode(Scopes)}";
And open this in a WebViewer inside the UWP and match on NavigationCompleted if the current Uri matches my RedirectUri and if so, I extract the Code for using to get the Tokens. Until this point everything is working well, but when I try to get the tokens
with this way:
List<KeyValuePair<string, string>> values = new List<KeyValuePair<string, string>>()
{
new KeyValuePair<string, string>("grant_type", "authorization_code"),
new KeyValuePair<string, string>("redirect_uri", RedirectUrl),
new KeyValuePair<string, string>("client_id", ClientId),
new KeyValuePair<string, string>("client_secret", ClientSecret),
new KeyValuePair<string, string>("code", code),
};
HttpClient client = new HttpClient();
FormUrlEncodedContent queryContent = new FormUrlEncodedContent(values);
var response = await client.PostAsync("https://login.microsoftonline.com/consumers/oauth2/v2.0/token", queryContent);
string responseContent = await response.Content.ReadAsStringAsync();
All I get is:
{"error":"invalid_grant","error_description":"AADSTS70000: The provided value for the 'redirect_uri' is not valid. The value must exactly match the redirect URI used to obtain the authorization code.
Trace ID: b85f6e60-53de-48d3-b373-0a0a71736a71
Correlation ID: c1972daa-8e59-447a-8574-1cba608ce64b
Timestamp: 2017-01-22 17:08:28Z","error_codes":[70000],"timestamp":"2017-01-22 17:08:28Z","trace_id":"b85f6e60-53de-48d3-b373-0a0a71736a71","correlation_id":"c1972daa-8e59-447a-8574-1cba608ce64b"
}
But the RedirectUri's cant be unequal though its the same Variable which is referenced and its still the same in the App Portal.
And I googled around, and tried that with the trailing slash at the end of the uri and I'm getting still the same error.
Does anyone have an idea?