Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Redirect to UWP app from OAuth without ms-app

Tags:

c#

oauth

uwp

I'm trying to write an app that communicates with an OAuth URL. Communication with the OAuth URL behaves appropriately, and the user is correctly prompted to log in. However, due to restrictions in the redirect URL for the app, I am unable to redirect to an ms-app domain (which I believe is how you open a UWP app on Windows 10 - please correct me if this assumption is incorrect!).

Other than hosting my own website and having a redirect created, does anyone know how to do this?

The code I'm currently using for the client is the sample code:

try
{
    var webAuthenticationResult = await WebAuthenticationBroker.AuthenticateAsync(WebAuthenticationOptions.None, url);

    switch (webAuthenticationResult.ResponseStatus)
    {
        case WebAuthenticationStatus.Success:
            // Successful authentication. 
            result = webAuthenticationResult.ResponseData.ToString();
            break;

        case WebAuthenticationStatus.ErrorHttp:
            // HTTP error. 
            result = webAuthenticationResult.ResponseErrorDetail.ToString();
            break;

        default:
            // Other error.
            result = webAuthenticationResult.ResponseData.ToString();
            break;
    }
}
catch (Exception ex)
{
    // Authentication failed. Handle parameter, SSL/TLS, and Network Unavailable errors here. 
    result = ex.Message;
}

The issue manifests itself like this:

Error reads: "We can't connect to the service you need right now. Check your network connection or try this again later."

like image 254
Nathan White Avatar asked Jul 23 '17 16:07

Nathan White


2 Answers

In UWP you can bind a protocol to your app through deep-linking, so that it opens by default any URL using that protocol.

More about deep-linking here.

Basically you create your own protocol (by creating I mean you just invent a string sequence like "my-great-protocol://") and register your app to respond to it, it doesn't have to be ms-app://.

If you really cannot link to anything but standard protocols, you can use an URL shortener service which will then redirect to your custom protocol. Not many URL shortening services allow this, but here is one that does: https://ipkill.org

like image 166
brett Avatar answered Nov 15 '22 20:11

brett


Are you trying to register a custom redirect scheme which opens up after login. For example redirect-uri=ms-app://test1 should open the custom scheme, Refer this link to learn how to register custom URI scheme. Once the custom uri scheme is invoked you can have this custom scheme to invoke your UWP app. Custom URI scheme comprises of a script (Shell or batch script for windows). You can write a line to invoke your UWP app.

like image 1
Venkatesh Marepalli Avatar answered Nov 15 '22 19:11

Venkatesh Marepalli