0

I have a project where I am running headed (w/ monitor) on my Rasp Pi 2 and have it connected to the internet so I can get data from services hosted 3rd party as well as those I have stood up in Azure.

All of the REST calls are working fine. However, the oAuth portion of the google calendar call works only on my development machines and other machines with a built in browser.

Is there a way I can save whatever tokens get generated from a debug run on my dev machine and take that into the deployment on to the RP2?

I have my client_secret.json file properties in my .sln Build Action = Content and Copy to Output Directory = Copy Always

The code I have that works on my dev machines:

var credential = await GoogleWebAuthorizationBroker.AuthorizeAsync(
                        new Uri("ms-appx:///client_secret.json"),
                        new[] { Uri.EscapeUriString(CalendarService.Scope.Calendar) },
                        calendarOwner,
                        CancellationToken.None);

        var calendarService = new CalendarService(new BaseClientService.Initializer
        {
            HttpClientInitializer = credential,
            ApplicationName = "myappname"
        });

        var calendarListResource = await calendarService.CalendarList.List().ExecuteAsync();

Any help or insight as to how I can get this running on my rp2 would be GREATLY appreciated! This is my first big stab at anything rp2 + win10iot stuff.

UPDATE: The exception I am receiving is as follows: Error:"UserCancel", Description:"The WebAuthenticationBroker didn't return a code or an error. Details:0", Uri:"" It jumps right to my catch block when axecuting AuthorizeAsync() method.

Scott Root
  • 582
  • 4
  • 6

1 Answers1

1

[UPDATE] I got some new information, that might be helpful for you too. Authentification via OAuth is provided by a Browser Window. There is no Browser included in Win 10 IOT, so that is not possible. According to this blogpost, I am trying to implement headless authentication, using an other device as described here.

[Old Post] Sorry, I am no help at the moment, but I'm looking for a solution for this problem as well. I Try to authenticate against my Azure AD with the WebAccountProvider. Deploying on a local machine works pretty fine, but while deploying to my RaspberryPi running Windows 10 IOT, the "Windows" to enter the credentials doesn't even open!

My Code (according to Jason Lattimers Blogpost):

public static class CurrentEnvironment
{
    # region Class Level Members
    private const string _clientID = "[MYCLIENTID]";
    public const string CrmServiceUrl = "https://MYCRMORG.crm4.dynamics.com";
    private const string _authority = "https://login.microsoftonline.com/common/oauth2/authorize";
    private static string _accessToken;

    # endregion

    public static async Task<string> Initialize()
    {
        //var redirect = GetAppRedirectURI();
        try
        {
            WebAccountProvider wap =
                    await WebAuthenticationCoreManager.FindAccountProviderAsync("https://login.microsoft.com", _authority);

            WebTokenRequest wtr = new WebTokenRequest(wap, string.Empty, _clientID);
            wtr.Properties.Add("resource", CrmServiceUrl);
            WebTokenRequestResult wtrr = await WebAuthenticationCoreManager.RequestTokenAsync(wtr);

            if (wtrr.ResponseStatus == WebTokenRequestStatus.Success)
            {
                _accessToken = wtrr.ResponseData[0].Token;
            }

        }
        catch (Exception ex)
        {

        }

        return _accessToken;}
mahu
  • 297
  • 1
  • 3
  • 14
  • While I didn't "solve" the issue I was having, and I am sure more will want to know how to OAuth via Win 10 IoT, I did "workaround" the problem by standing up a web api service in Azure and using that to hit Google calendar with a service account. Many steps out of the way but it solved my immediate needs. – Scott Root Feb 04 '16 at 18:24
  • This article here does mention though how to "create" a browser in UWP by using a web viewer type of control which may work if you can make it spawn open with a good url: http://www.instructables.com/id/Coding-Web-Browser-for-Windows-10-IOT-on-Raspberry/?ALLSTEPS – Scott Root Feb 04 '16 at 18:25