I'm doing OAuth2 authentication in my Windows Phone 8.1 app and I'm using the WebAuthenticationBroker
with the AuthenticateAndContinue()
method for WP.
I'm authenticating to my server where I send two parameters and it returns my access token, without any other step in and between. Given this situation I don't have a callbakUri, so I use the WebAuthenticationBroker.GetCurrentApplicationCallbackUri()
My code looks like this:
Uri endpointURL = new Uri(_requestUrl + "&client_id=" + clientId + "&client_secret=" + clientSecret);
Uri callbackUri = WebAuthenticationBroker.GetCurrentApplicationCallbackUri();
WebAuthenticationBroker.AuthenticateAndContinue(endpointURL, callbackUri, null, WebAuthenticationOptions.None);
I have the ContinuationManager.cs
class in my project, as well as all the changed needed in the App.xaml.cs
, as described here: http://msdn.microsoft.com/en-us/library/dn631755.aspx
My problem is that after I execute the code above, the Continue()
method in the ContinuationManager
class is never executed, so my app blocks there.
Am I missing something here?
WebAuthenticationBroker.AuthenticateAndContinue
knows the authentication is done when the user is redirected to a specific page.
There's two way to deal with it:
Most services accept a parameter to set the URI the user is redirected to (the parameter is often called callback
. In that case, you can generate an URI with WebAuthenticationBroker.GetCurrentApplicationCallbackUri
and pass it to the WebAuthenticationBroker.AuthenticateAndContinue
method (as you're doing in your code sample)
If the service doesn't accept a callback parameter, then you need to do things the other way: first check what URI the service redirects too (by calling it manually once), then pass this URI to the WebAuthenticationBroker.AuthenticateAndContinue
method. For instance, let's say the OAuth service redirects to http://www.stackoverflow.com, then you need to call:
WebAuthenticationBroker.AuthenticateAndContinue(endpointURL, new Uri("http://www.stackoverflow.com"), null, WebAuthenticationOptions.None);