Exemple #1
0
        /// <summary>
        /// Creates a new <see cref="IPublicClientApplication"/>
        /// </summary>
        /// <param name="clientId">Client ID (also known as <i>Application ID</i>) of the application as registered in the application registration portal (https://aka.ms/msal-net-register-app).</param>
        /// <param name="tokenStorageProvider">A <see cref="ITokenStorageProvider"/> for storing and retrieving access token.</param>
        /// <param name="tenant">Tenant to sign-in users. This defaults to <c>organizations</c> if non is specified.</param>
        /// <param name="nationalCloud">A <see cref="NationalCloud"/> which identifies the national cloud endpoint to use as the authority. This defaults to the global cloud <see cref="NationalCloud.Global"/> (https://login.microsoftonline.com).</param>
        /// <returns>A <see cref="IPublicClientApplication"/></returns>
        public static IPublicClientApplication CreateClientApplication(string clientId,
                                                                       ITokenStorageProvider tokenStorageProvider = null,
                                                                       string tenant = null,
                                                                       NationalCloud nationalCloud = NationalCloud.Global)
        {
            TokenCacheProvider tokenCacheProvider = new TokenCacheProvider(tokenStorageProvider);
            string             authority          = NationalCloudHelpers.GetAuthority(nationalCloud, tenant ?? AuthConstants.Tenants.Organizations);

            return(new PublicClientApplication(clientId, authority, tokenCacheProvider.GetTokenCacheInstnce()));
        }
Exemple #2
0
        /// <summary>
        /// Creates a new <see cref="IConfidentialClientApplication"/>
        /// </summary>
        /// <param name="clientId">Client ID (also known as <i>Application ID</i>) of the application as registered in the application registration portal (https://aka.ms/msal-net-register-app)</param>
        /// <param name="clientCredential">A <see cref="Microsoft.Identity.Client.ClientCredential"/> created either from an application secret or a certificate</param>
        /// <param name="tokenStorageProvider">A <see cref="ITokenStorageProvider"/> for storing and retrieving access token. </param>
        /// <param name="tenant">Tenant to sign-in users. This defaults to <c>common</c> if non is specified</param>
        /// <param name="nationalCloud">A <see cref="NationalCloud"/> which identifies the national cloud endpoint to use as the authority. This defaults to the global cloud <see cref="NationalCloud.Global"/> (https://login.microsoftonline.com) </param>
        /// <returns>A <see cref="IConfidentialClientApplication"/></returns>
        public static IConfidentialClientApplication CreateClientApplication(string clientId,
                                                                             ClientCredential clientCredential,
                                                                             ITokenStorageProvider tokenStorageProvider = null,
                                                                             string tenant = null,
                                                                             NationalCloud nationalCloud = NationalCloud.Global)
        {
            TokenCacheProvider tokenCacheProvider = new TokenCacheProvider(tokenStorageProvider);
            string             authority          = NationalCloudHelpers.GetAuthority(nationalCloud, tenant ?? AuthConstants.Tenants.Common);

            return(new ConfidentialClientApplication(clientId, authority, string.Empty, clientCredential, null, tokenCacheProvider.GetTokenCacheInstnce()));
        }
Exemple #3
0
        public void GetAuthority_ShouldGetAuthorityForNationalCloud()
        {
            string authority = NationalCloudHelpers.GetAuthority(NationalCloud.UsGovernment, "test");

            Assert.AreEqual("https://login.microsoftonline.us/test/", authority);
        }