예제 #1
0
        /// <summary>
        /// Shows the Google authentication web view so the user can authenticate
        /// </summary>
        async Task ShowGoogleAuthenticationView()
        {
            if (RoomieApp.AuthToken != null && Settings.Instance.User != null)
            {
                var success = await GetUserProfile();

                if (success)
                {
                    AzureService.Instance.Client.CurrentUser = Settings.Instance.User;
                    return;
                }
            }

            try
            {
                AuthenticationStatus = "Loading...";
                MobileServiceUser user = await _authenticator.DisplayWebView();

                var identity = await AzureService.Instance.Client.InvokeApiAsync("getUserIdentity", null, HttpMethod.Get, null);

                RoomieApp.AuthToken = identity.Value <string>("accessToken");
                //Utility.SetSecured("AuthToken", App.AuthToken, "vdoers.roomie", "authentication");

                Settings.Instance.User = user;
                await Settings.Instance.Save();

                if (RoomieApp.CurrentRoomie != null && RoomieApp.CurrentRoomie.Id != null)
                {
                    var task = AzureService.Instance.SaveRoomie(RoomieApp.CurrentRoomie);
                    await RunSafe(task);
                }
            }
            catch (Exception e)
            {
                Debug.WriteLine("**ROOMIE AUTHENTICATION ERROR**\n\n" + e.GetBaseException());
                // InsightsManager.Report(e);
            }
        }