Exemple #1
0
        protected async override void OnNavigatedTo(NavigationEventArgs e)
        {
            try
            {
                var wap = await WebAuthenticationCoreManager.FindAccountProviderAsync("https://login.microsoft.com", "organizations");

                WebTokenRequest wtr      = new WebTokenRequest(wap, string.Empty, "ba789272-8d97-425c-9cdf-e43c6e76d73c");
                const string    resource = "https://graph.windows.net";
                //wtr.Properties.Add("resource", resource);
                WebTokenRequestResult wtrr = await WebAuthenticationCoreManager.RequestTokenAsync(wtr);

                if (wtrr.ResponseStatus == WebTokenRequestStatus.Success)
                {
                    var userAccount = wtrr.ResponseData[0].WebAccount;
                }
                else
                {
                    var x = wtrr.ResponseError;
                }
            }
            catch (Exception ex)
            {
                var s = ex.Message;
            }
        }
        private async void UIElement_OnTapped(object sender, TappedRoutedEventArgs e)
        {
            try
            {
                // Check whether there is an app for the provider we want to use (facebook)
                var provider = await WebAuthenticationCoreManager.FindAccountProviderAsync("https://www.facebook.com");

                if (provider != null)
                {
                    var response = await GetToken(provider, true);

                    if (response != null)
                    {
                        // We have the response token, so we can check if we are authenticated.
                        await ProcessResponse(response, provider);
                    }
                    else
                    {
                        // Ok, so now we need to tell Facebook to give us the token and possibly sign in
                        Fallbacks();
                    }
                }
                else
                {
                    // Use alternative methods
                    Fallbacks();
                }
            }
            catch (Exception ex)
            {
                var i = 1;
            }
        }
        private static async Task <WebTokenResponse> RequestTokenAsync(bool forceLogin)
        {
            // [SCENARIO] OAuth 2.0 Authorization Code Grant, Public Client
            // Get a token to authenticate against the Web API.
            var promptType = forceLogin ? WebTokenRequestPromptType.ForceAuthentication : WebTokenRequestPromptType.Default;
            var provider   = await WebAuthenticationCoreManager.FindAccountProviderAsync("https://login.microsoft.com/", AppConfiguration.AccountProviderAuthority);

            var request = new WebTokenRequest(provider, string.Empty, AppConfiguration.TodoListWindows10ClientId, promptType);

            request.Properties.Add("resource", AppConfiguration.TodoListWebApiResourceId);
            request.Properties.Add("authority", AppConfiguration.StsAuthority);
            // Skip authority validation for AD FS, otherwise you get the following error:
            // ERROR: The value specified for 'authority' is invalid. It is not in the valid authority list or not discovered. (3399548934)
            request.Properties.Add("validateAuthority", AppConfiguration.CanValidateAuthority.ToString());

            var result = await WebAuthenticationCoreManager.RequestTokenAsync(request);

            if (result.ResponseStatus == WebTokenRequestStatus.Success)
            {
                // [NOTE] At this point we have the authentication result, including the user information.
                // From this point on we can use the regular OAuth 2.0 Bearer Token to call the Web API.
                return(result.ResponseData.Single());
            }
            else if (result.ResponseStatus != WebTokenRequestStatus.UserCancel)
            {
                var errorMessage = result.ResponseError == null ? "Unknown error" : result.ResponseError.ErrorMessage;
                throw new Exception(errorMessage);
            }
            else
            {
                return(null);
            }
        }
        public static async Task <List <Tuple <string, string> > > GetMSAccounts()
        {
            WebAccountProvider provider = await WebAuthenticationCoreManager.FindAccountProviderAsync("https://login.microsoft.com", "consumers");

            int status = GetMSAccounts(out string[] accountNames, out string[] accountIds, out int accountCount);

            if (status >= ZL_ERRORS_START && status <= ZL_ERRORS_END)
            {
                throw new BackendException(status);
            }
            else if (status != 0)
            {
                Marshal.ThrowExceptionForHR(status);
            }
            var accounts = accountNames.Zip(accountIds, Tuple.Create).ToList();

            foreach (var account in accounts.ToList())
            {
                if (await WebAuthenticationCoreManager.FindAccountAsync(provider, account.Item2) == null)
                {
                    accounts.Remove(account);
                }
            }
            return(accounts);
        }
        /// <summary>
        /// Creates an AccountsSettingsPane with options for MSA or Facebook login.
        /// </summary>
        private static async void BuildSettingsPaneAsync(AccountsSettingsPane s,
                                                         AccountsSettingsPaneCommandsRequestedEventArgs e)
        {
            var deferral = e.GetDeferral();

            e.HeaderText = _paneMessage + "Get signed in to Lunch Scheduler.  " +
                           "You can use an existing Microsoft or Facebook account.";

            // Microsoft account
            var msa = new WebAccountProviderCommand(
                await WebAuthenticationCoreManager.FindAccountProviderAsync("https://login.microsoft.com", "consumers"),
                MicrosoftAccountAuth);

            e.WebAccountProviderCommands.Add(msa);

            // Facebook
            // Built-in provider exists only on phone; if not availble, use WAB as a fallback
            var fbProvider = await WebAuthenticationCoreManager.FindAccountProviderAsync("https://facebook.com");

            var fb = new WebAccountProviderCommand(
                fbProvider ??
                new WebAccountProvider("LunchScheduler", "Facebook", new Uri(@"ms-appx:///Assets/FbIcon.png")),
                FacebookAuth);

            e.WebAccountProviderCommands.Add(fb);

            // Help commands
            e.Commands.Add(new SettingsCommand("help", "Get help signing in",
                                               async x => await Launcher.LaunchUriAsync(new Uri("http://bing.com"))));
            e.Commands.Add(new SettingsCommand("privacy", "Privacy policy",
                                               async x => await Launcher.LaunchUriAsync(new Uri("http://bing.com"))));

            deferral.Complete();
        }
        /// <summary>
        /// Signs the current user out and clears his account information.
        /// </summary>
        public async Task SignOutAccountAsync()
        {
            if (ApplicationData.Current.LocalSettings.Values.ContainsKey(CurrentUserKey))
            {
                WebAccountProvider providertoDelete = await WebAuthenticationCoreManager.FindAccountProviderAsync(
                    MicrosoftAccountProviderId,
                    ConsumerAuthority);

                WebAccount accountToDelete = await WebAuthenticationCoreManager.FindAccountAsync(
                    providertoDelete,
                    (string)ApplicationData.Current.LocalSettings.Values[CurrentUserKey]);

                if (accountToDelete != null)
                {
                    await accountToDelete.SignOutAsync();
                }

                ApplicationData.Current.LocalSettings.Values.Remove(CurrentUserKey);
                ApplicationData.Current.LocalSettings.Values.Remove(CurrentUserProviderKey);

                UserIsSignedIn = false;
                UserSignInChange(this, false);

                Debug.WriteLine("Successfully logged out");
            }
        }
Exemple #7
0
        //retrieving token from storage
        public async Task <string> GetTokenSilentlyAsync()
        {
            string providerId = ApplicationData.Current.LocalSettings.Values["CurrentUserProviderId"]?.ToString();
            string accountId  = ApplicationData.Current.LocalSettings.Values["CurrentUserId"]?.ToString();

            if (null == providerId || null == accountId)
            {
                return(null);
            }
            WebAccountProvider provider = await WebAuthenticationCoreManager.FindAccountProviderAsync(providerId);

            WebAccount account = await WebAuthenticationCoreManager.FindAccountAsync(provider, accountId);

            WebTokenRequest       request = new WebTokenRequest(provider, "wl.basic");
            WebTokenRequestResult result  = await WebAuthenticationCoreManager.GetTokenSilentlyAsync(request, account);

            if (result.ResponseStatus == WebTokenRequestStatus.UserInteractionRequired)
            {
                // Unable to get a token silently - you'll need to show the UI
                return(null);
            }
            else if (result.ResponseStatus == WebTokenRequestStatus.Success)
            {
                // Success
                return(result.ResponseData[0].Token);
            }
            else
            {
                // Other error
                return(null);
            }
        }
        private async Task <WebTokenRequestResult?> SilentAuthAsync()
        {
            // Ref: https://docs.microsoft.com/en-us/windows/uwp/security/web-account-manager#store-the-account-for-future-use

            string providerId = _userSettings.Get <string>(UserSettingsConstants.CurrentUserProviderId);
            string accountId  = _userSettings.Get <string>(UserSettingsConstants.CurrentUserId);

            if (string.IsNullOrWhiteSpace(providerId) || string.IsNullOrWhiteSpace(accountId))
            {
                return(null);
            }

            try
            {
                WebAccountProvider provider = await WebAuthenticationCoreManager.FindAccountProviderAsync(providerId);

                WebAccount account = await WebAuthenticationCoreManager.FindAccountAsync(provider, accountId);

                WebTokenRequest       request = new WebTokenRequest(provider, Scope, _clientId);
                WebTokenRequestResult result  = await WebAuthenticationCoreManager.GetTokenSilentlyAsync(request, account);

                return(result);
            }
            catch
            {
                return(null);
            }
        }
        private async Task AddWebAccount(AccountsSettingsPaneCommandsRequestedEventArgs e)
        {
            WebAccountProvider provider = await WebAuthenticationCoreManager.FindAccountProviderAsync(MicrosoftAccountProviderId, ConsumerAuthority);

            String     accountID = (String)ApplicationData.Current.LocalSettings.Values[StoredAccountKey];
            WebAccount account   = await WebAuthenticationCoreManager.FindAccountAsync(provider, accountID);

            WebAccountProvider web      = new WebAccountProvider("818", "MicrosoftAccount", new Uri("ms-appdata:///local/ProfilePicture.jpg"));
            WebAccount         account2 = new WebAccount(web, (string)ApplicationData.Current.LocalSettings.Values[StoredEmailKey], WebAccountState.Connected);

            if (account == null)
            {
                ApplicationData.Current.LocalSettings.Values.Remove(StoredAccountKey);
            }
            if (ApplicationData.Current.LocalSettings.Values.ContainsKey(StoredEmailKey))
            {
                WebAccountCommand command = new WebAccountCommand(account2, WebAccountInvoked, SupportedWebAccountActions.Remove);
                e.WebAccountCommands.Add(command);
            }
            else
            {
                WebAccountCommand command = new WebAccountCommand(account, WebAccountInvoked, SupportedWebAccountActions.Remove);
                e.WebAccountCommands.Add(command);
            }
        }
Exemple #10
0
        public async Task <string> GetAccessTokenForResource(string resource)
        {
            string token = null;

            //first try to get the token silently
            WebAccountProvider aadAccountProvider = await WebAuthenticationCoreManager.FindAccountProviderAsync("https://login.windows.net");

            WebTokenRequest webTokenRequest = new WebTokenRequest(aadAccountProvider, String.Empty, App.Current.Resources["ida:ClientID"].ToString(), WebTokenRequestPromptType.Default);

            webTokenRequest.Properties.Add("authority", "https://login.windows.net");
            webTokenRequest.Properties.Add("resource", resource);
            WebTokenRequestResult webTokenRequestResult = await WebAuthenticationCoreManager.GetTokenSilentlyAsync(webTokenRequest);

            if (webTokenRequestResult.ResponseStatus == WebTokenRequestStatus.Success)
            {
                WebTokenResponse webTokenResponse = webTokenRequestResult.ResponseData[0];
                token = webTokenResponse.Token;
            }
            else if (webTokenRequestResult.ResponseStatus == WebTokenRequestStatus.UserInteractionRequired)
            {
                //get token through prompt
                webTokenRequest = new WebTokenRequest(aadAccountProvider, String.Empty, App.Current.Resources["ida:ClientID"].ToString(), WebTokenRequestPromptType.ForceAuthentication);
                webTokenRequest.Properties.Add("authority", "https://login.windows.net");
                webTokenRequest.Properties.Add("resource", resource);
                webTokenRequestResult = await WebAuthenticationCoreManager.RequestTokenAsync(webTokenRequest);

                if (webTokenRequestResult.ResponseStatus == WebTokenRequestStatus.Success)
                {
                    WebTokenResponse webTokenResponse = webTokenRequestResult.ResponseData[0];
                    token = webTokenResponse.Token;
                }
            }

            return(token);
        }
Exemple #11
0
        public async System.Threading.Tasks.Task <string> GetAzureADUserInteractiveTokenUWP(string ApplicationID, string tenantDomain)
        {
            string token     = string.Empty;
            string authority = "https://login.microsoftonline.com/" + tenantDomain;

            try
            {
                //                WebAccountProvider wap = await WebAuthenticationCoreManager.FindAccountProviderAsync("https://login.microsoft.com", authority);
                WebAccountProvider wap = await WebAuthenticationCoreManager.FindAccountProviderAsync("https://login.microsoftonline.com/", authority);

                string          resource = "https://rest.media.azure.net";
                WebTokenRequest wtr      = new WebTokenRequest(wap, string.Empty, ApplicationID);
                if (wtr != null)
                {
                    wtr.Properties.Add("resource", resource);
                    WebTokenRequestResult wtrr = await WebAuthenticationCoreManager.RequestTokenAsync(wtr);

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

                        var account = wtrr.ResponseData[0].WebAccount;

                        var properties = wtrr.ResponseData[0].Properties;
                    }
                }
            }
            catch (Exception e)
            {
                LogMessage("Exception " + e.Message);
                token = string.Empty;
            }
            return(token);
        }
        /// <summary>
        /// Add items to the AccountsSettingsPane
        /// </summary>
        /// <param></param>
        /// <returns></returns>
        public static async Task <ImageMenuItem> AutoSignIn()
        {
            IReadOnlyList <User> users = await User.FindAllAsync();

            if (users.Count != 0)
            {
                User user = User.GetFromId(users.ElementAt(0).NonRoamableId);
                provider = await WebAuthenticationCoreManager.FindAccountProviderAsync(MicrosoftAccountProviderId, ConsumerAuthority, user);

                request = new WebTokenRequest(provider, GraphScope, AccountClientId);
                token   = await GetTokenSilently();

                if (token != null)
                {
                    ImageMenuItem userDetails = await GetUser(token, FirstName);

                    return(userDetails);
                }
                else
                {
                    return(null);
                }
            }
            return(null);
        }
Exemple #13
0
        protected override async Task <WebTokenResponse> GetToken(string resource, string authority = null)
        {
            if (authority == null)
            {
                authority = Authority;
            }
            else
            {
                authority = $"{LoginBase}/{authority}";
            }

            WebAccountProvider wap = await WebAuthenticationCoreManager.FindAccountProviderAsync("https://login.microsoft.com", authority);

            var tokenRequest = new WebTokenRequest(wap, string.Empty, AppClientId);

            tokenRequest.Properties.Add("resource", resource);
            try
            {
                var tokenResponse = await WebAuthenticationCoreManager.RequestTokenAsync(tokenRequest);

                if (tokenResponse.ResponseStatus != WebTokenRequestStatus.Success)
                {
                    throw new Exception(tokenResponse.ResponseError.ErrorMessage);
                }
                return(tokenResponse.ResponseData.Single());
            }
            catch
            {
                throw;
            }
        }
Exemple #14
0
        public static async Task <bool> LogOut()
        {
            WebAccountProvider wap = await WebAuthenticationCoreManager.FindAccountProviderAsync("https://login.microsoft.com", authority);

            //Getting redirect url
            //string URI = string.Format("ms-appx-web://Microsoft.AAD.BrokerPlugIn/{0}", WebAuthenticationBroker.GetCurrentApplicationCallbackUri().Host.ToUpper());
            //resource = URI;

            WebTokenRequest wtr = new
                                  WebTokenRequest(wap, string.Empty, clientId);

            wtr.Properties.Add("resource", resource);
            WebTokenRequestResult wtrr = await WebAuthenticationCoreManager.RequestTokenAsync(wtr);

            if (wtrr.ResponseStatus == WebTokenRequestStatus.Success)

            {
                var account = wtrr.ResponseData[0].WebAccount;
                await account.SignOutAsync();

                return(true);
            }
            else
            {
                return(false);
            }
        }
Exemple #15
0
        private async Task GetProvider()
        {
            try
            {
                IAsyncOperation <WebAccountProvider> provider = WebAuthenticationCoreManager.FindAccountProviderAsync("login.windows.local");//login.windows.local


                //int count = 5;

                //while(provider.Status != AsyncStatus.Completed && count > 0)
                //{
                //    Thread.Sleep(200);
                //    count--;
                //}

                var result = await provider.AsTask();

                if (result != null)
                {
                    Console.WriteLine(result.DisplayName);
                    Console.WriteLine(result.DisplayPurpose);
                    Console.WriteLine(result.Id);
                }
                else
                {
                    Console.WriteLine("there is no default account is setup for the user");
                }
            }
            catch (Exception ex)
            {
                ex.ToString();
            }
        }
        public static async Task <string> GetTokenForUserAsync()
        {
            //for most Enteprise apps, we only care about AAD version of MSGraph
            string authority = "organizations";
            // string resource = "https://graph.windows.net";   // This is the Azure AD Graph not MS Graph...
            string resource     = "https://graph.microsoft.com"; //Microsoft Graph
            string TokenForUser = null;

            var wap = await WebAuthenticationCoreManager.FindAccountProviderAsync("https://login.microsoft.com", authority);

            // craft the token request for the Graph api
            //What is the correct scope?
            WebTokenRequest wtr = new WebTokenRequest(wap, _scopes, _clientId);

            wtr.Properties.Add("resource", resource);

            WebTokenRequestResult wtrr = await WebAuthenticationCoreManager.RequestTokenAsync(wtr);

            if (wtrr.ResponseStatus == WebTokenRequestStatus.Success)
            {
                TokenForUser = wtrr.ResponseData[0].Token;
            }
            else
            {
                System.Diagnostics.Debug.WriteLine(wtrr.ResponseError);
            }
            return(TokenForUser);
        }
Exemple #17
0
        public async Task <bool> IsDefaultAccountMsaAsync()
        {
            // provider for the "default" account
            var provider = await WebAuthenticationCoreManager.FindAccountProviderAsync("https://login.windows.local");

            return(provider != null && string.Equals(Constants.ConsumerTenant, provider.Authority));
        }
Exemple #18
0
        private async Task <WebAccount> GetWebAccount()
        {
            String accountID  = ApplicationData.Current.LocalSettings.Values[Constants.StoredAccountIdKey] as String;
            String providerID = ApplicationData.Current.LocalSettings.Values[Constants.StoredProviderIdKey] as String;

            WebAccount account = null;

            try
            {
                WebAccountProvider provider = await WebAuthenticationCoreManager.FindAccountProviderAsync(providerID);

                account = await WebAuthenticationCoreManager.FindAccountAsync(provider, accountID);

                // The account has been deleted if FindAccountAsync returns null
                if (account == null)
                {
                    DebugPrint("cannot find the account, which might be removed from Settings.");
                    RemoveAccountData();
                }
            }
            catch (Exception ex)
            {
                DebugPrint("GetWebAccount exception: " + ex.Message);
            }

            return(account);
        }
Exemple #19
0
        public async Task <WebAccountProvider> GetAccountProviderAsync(string authorityOrTenant)
        {
            WebAccountProvider provider = await WebAuthenticationCoreManager.FindAccountProviderAsync(
                "https://login.microsoft.com",
                authorityOrTenant);

            return(provider);
        }
        private async Task AddWebAccountProvider(AccountsSettingsPaneCommandsRequestedEventArgs e)
        {
            WebAccountProvider provider = await WebAuthenticationCoreManager.FindAccountProviderAsync(MicrosoftAccountProviderId, ConsumerAuthority);

            WebAccountProviderCommand providerCommand = new WebAccountProviderCommand(provider, WebAccountProviderCommandInvoked);

            e.WebAccountProviderCommands.Add(providerCommand);
        }
Exemple #21
0
 private async Task <WebAccountProvider> GetProvider()
 {
     if (_wap == null)
     {
         _wap = await WebAuthenticationCoreManager.FindAccountProviderAsync(ProviderId, _authority);
     }
     return(_wap);
 }
Exemple #22
0
        public async void AuthenticateWithRequestToken(
            String WebAccountProviderID,
            String Authority,
            String Scope,
            String ClientID,
            String TokenBindingTarget,
            String RequestProperties)
        {
            try
            {
                //
                //create webTokenRequest with ProviderID, Scope, ClientId
                //
                DebugPrint("creating the webAccountProviderID");

                WebAccountProvider provider = null;
                if (String.IsNullOrEmpty(Authority))
                {
                    DebugPrint("calling FindAccountProviderAsync...");
                    provider = await WebAuthenticationCoreManager.FindAccountProviderAsync(WebAccountProviderID);
                }
                else
                {
                    DebugPrint("calling FindAccountProviderWithAuthorityAsync...");
                    provider = await WebAuthenticationCoreManager.FindAccountProviderAsync(
                        WebAccountProviderID,
                        Authority);
                }

                DebugPrint("Provider Id: " + provider.Id);
                DebugPrint("Provider DisplayName: " + provider.DisplayName);

                WebTokenRequestPromptType prompt = ForceUiCheckBox.IsChecked.Value ?
                                                   WebTokenRequestPromptType.ForceAuthentication : WebTokenRequestPromptType.Default;

                WebTokenRequest webTokenRequest = new WebTokenRequest(
                    provider,
                    Scope,
                    ClientID,
                    prompt);

                //
                // add properties to the tokenrequest if the IDP plugin requires
                //

                AddRequestProperties(RequestProperties, webTokenRequest);

                DebugPrint("Call RequestTokenAsync");
                WebTokenRequestResult webTokenRequestResult = await WebAuthenticationCoreManager.RequestTokenAsync(webTokenRequest);

                HandleResult(webTokenRequestResult);
            }
            catch (Exception ex)
            {
                DebugPrint("RequestToken failed: " + ex.Message);
            }
        }
Exemple #23
0
 public async Task Initialize()
 {
     if (AccountProvider == null)
     {
         AccountProvider = await WebAuthenticationCoreManager.FindAccountProviderAsync("https://login.microsoft.com", Authority);
     }
     if (AppSettings == null)
     {
         AppSettings = ApplicationData.Current.RoamingSettings;
     }
 }
    private static async Task <string> GetXTokenAsync()
    {
        string token = string.Empty;

        // Get an XToken
        // Find the account provider using the signed in user.
        // We always use the 1st signed in user, because we just need a valid token. It doesn't
        // matter who's it is.
        Windows.System.User currentUser;
        WebTokenRequest     request;
        var users = await Windows.System.User.FindAllAsync();

        currentUser = users[0];
        WebAccountProvider xboxProvider = await WebAuthenticationCoreManager.FindAccountProviderAsync("https://xsts.auth.xboxlive.com", "", currentUser);

        // Build the web token request using the account provider.
        // Url = URL of the service we are getting a token for - for example https://apis.mycompany.com/something.
        // As this is a sample just use xboxlive.com
        // Target & Policy should always be set to "xboxlive.signin" and "DELEGATION"
        // For this call to succeed your console needs to be in the XDKS.1 sandbox
        request = new Windows.Security.Authentication.Web.Core.WebTokenRequest(xboxProvider);
        request.Properties.Add("Url", "https://xboxlive.com");
        request.Properties.Add("Target", "xboxlive.signin");
        request.Properties.Add("Policy", "DELEGATION");

        // Request a token - correct pattern is to call getTokenSilentlyAsync and if that
        // fails with WebTokenRequestStatus.userInteractionRequired then call requestTokenAsync
        // to get the token and prompt the user if required.
        // getTokenSilentlyAsync can be called on a background thread.
        WebTokenRequestResult tokenResult = await WebAuthenticationCoreManager.GetTokenSilentlyAsync(request);

        //If we got back a token call our service with that token
        if (tokenResult.ResponseStatus == WebTokenRequestStatus.Success)
        {
            token = tokenResult.ResponseData[0].Token;
        }
        else if (tokenResult.ResponseStatus == WebTokenRequestStatus.UserInteractionRequired)
        { // WebTokenRequestStatus.userInteractionRequired = 3
          // If user interaction is required then call requestTokenAsync instead - this will prompt for user permission if required
          // Note: RequestTokenAsync cannot be called on a background thread.
            WebTokenRequestResult tokenResult2 = await WebAuthenticationCoreManager.RequestTokenAsync(request);

            //If we got back a token call our service with that token
            if (tokenResult2.ResponseStatus == WebTokenRequestStatus.Success)
            {
                token = tokenResult.ResponseData[0].Token;
            }
            else if (tokenResult2.ResponseStatus == WebTokenRequestStatus.UserCancel)
            {
                // No-op
            }
        }
        return(token);
    }
 private async Task <WebAccountProvider> GetProvider(string ProviderID, string AuthorityId = "")
 {
     if (ProviderID == AppSpecificProviderId)
     {
         return(new WebAccountProvider(AppSpecificProviderId, AppSpecificProviderName, new Uri(this.BaseUri, "Assets/smallTile-sdk.png")));
     }
     else
     {
         return(await WebAuthenticationCoreManager.FindAccountProviderAsync(ProviderID, AuthorityId));
     }
 }
Exemple #26
0
        private async void OnAccountCommandsRequested(AccountsSettingsPane sender, AccountsSettingsPaneCommandsRequestedEventArgs e)
        {
            AccountsSettingsPaneEventDeferral deferral = e.GetDeferral();

            WebAccountProvider provider = await WebAuthenticationCoreManager.FindAccountProviderAsync(ProviderId, Authority);

            WebAccountProviderCommand providerCommand = new WebAccountProviderCommand(provider, WebAccountProviderCommandInvoked);

            e.WebAccountProviderCommands.Add(providerCommand);

            deferral.Complete();
        }
Exemple #27
0
        private async void MainPage_AccountCommandsRequested(AccountsSettingsPane sender, AccountsSettingsPaneCommandsRequestedEventArgs args)
        {
            var d           = args.GetDeferral();
            var msaProvider = await WebAuthenticationCoreManager.FindAccountProviderAsync(
                "https://login.microsoft.com",
                "consumers");

            var command = new WebAccountProviderCommand(msaProvider, GetMsaTokenAsync);

            args.WebAccountProviderCommands.Add(command);
            d.Complete();
        }
Exemple #28
0
        private async void BuildPaneAsync(AccountsSettingsPane s,
                                          AccountsSettingsPaneCommandsRequestedEventArgs e)
        {
            var deferral    = e.GetDeferral();
            var msaProvider = await WebAuthenticationCoreManager.FindAccountProviderAsync(
                "https://login.microsoft.com", "consumers");

            var command = new WebAccountProviderCommand(msaProvider, GetMsaTokenAsync);

            e.WebAccountProviderCommands.Add(command);
            deferral.Complete();
        }
        public async Task <WebAccount> GetAccountAsync()
        {
            var webAccountProvider = await WebAuthenticationCoreManager.FindAccountProviderAsync(_settings.WebAccountProviderId, _settings.Authority);

            var userId = _appSettings.Values["userId"];

            if (string.IsNullOrWhiteSpace(userId as string))
            {
                return(null);
            }

            return(await WebAuthenticationCoreManager.FindAccountAsync(webAccountProvider, (string)userId));
        }
        private void InitializeProvider(User user)
        {
            IAsyncOperation <WebAccountProvider> provider;

            if (user != null && IsMultiUserApplication())
            {
                provider = WebAuthenticationCoreManager.FindAccountProviderAsync("https://xsts.auth.xboxlive.com", "", user);
            }
            else
            {
                provider = WebAuthenticationCoreManager.FindAccountProviderAsync("https://xsts.auth.xboxlive.com");
            }
            provider.Completed = FindAccountCompleted;
        }