/// <summary>
        /// Initializes a new instance of the <see cref="MsalProvider"/> class.
        /// </summary>
        /// <param name="client">Existing <see cref="IPublicClientApplication"/> instance.</param>
        /// <param name="provider">Existing <see cref="IAuthenticationProvider"/> instance.</param>
        /// <returns>A <see cref="Task"/> returning a <see cref="MsalProvider"/> instance.</returns>
        public static async Task <MsalProvider> CreateAsync(IPublicClientApplication client, IAuthenticationProvider provider)
        {
            //// TODO: Check all config provided

            var msal = new MsalProvider
            {
                Client   = client,
                Provider = provider,
                Graph    = new GraphServiceClient(provider)
            };

            await msal.TrySilentSignInAsync();

            return(msal);
        }
Beispiel #2
0
        public static async Task <MsalProvider> CreateMsalProviderAsync(string clientid, string redirectUri = "https://login.microsoftonline.com/common/oauth2/nativeclient", string[] scopes = null)
        {
            var client = PublicClientApplicationBuilder.Create(clientid)
                         .WithAuthority(AzureCloudInstance.AzurePublic, AadAuthorityAudience.AzureAdAndPersonalMicrosoftAccount)
                         .WithRedirectUri(redirectUri)
                         .WithClientName(ProviderManager.ClientName)
                         .WithClientVersion(Assembly.GetExecutingAssembly().GetName().Version.ToString())
#if __ANDROID__
                         .WithParentActivityOrWindow(() => Uno.UI.ContextHelper.Current as Android.App.Activity)
#endif
                         .Build();

            if (scopes == null)
            {
                scopes = new string[] { string.Empty };
            }

            var provider = new InteractiveAuthenticationProvider(client, scopes);

            return(await MsalProvider.CreateAsync(client, provider));
        }