예제 #1
0
        private AuthenticationParameters GetAuthenticationParameters(PartnerAccount account, PartnerEnvironment environment, IEnumerable <string> scopes, string message = null)
        {
            if (account.IsPropertySet(PartnerAccountPropertyType.AccessToken))
            {
                return(new AccessTokenParameters(account, environment, scopes));
            }
            else if (account.IsPropertySet("UseAuthCode"))
            {
                return(new InteractiveParameters(account, environment, scopes, message));
            }
            else if (account.IsPropertySet(PartnerAccountPropertyType.RefreshToken))
            {
                return(new RefreshTokenParameters(account, environment, scopes));
            }
            else if (account.Type == AccountType.User)
            {
                if (!string.IsNullOrEmpty(account.ObjectId))
                {
                    return(new SilentParameters(account, environment, scopes));
                }
                else if (account.IsPropertySet("UseDeviceAuth"))
                {
                    return(new DeviceCodeParameters(account, environment, scopes));
                }

                return(new InteractiveParameters(account, environment, scopes, message));
            }
            else if (account.Type == AccountType.ServicePrincipal || account.Type == AccountType.Certificate)
            {
                return(new ServicePrincipalParameters(account, environment, scopes));
            }

            return(null);
        }
예제 #2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="account"></param>
        /// <param name="environment"></param>
        /// <param name="redirectUri"></param>
        /// <returns></returns>
        public IClientApplicationBase GetClient(PartnerAccount account, PartnerEnvironment environment, string redirectUri = null)
        {
            IClientApplicationBase app;

            if (account.IsPropertySet(PartnerAccountPropertyType.CertificateThumbprint) || account.IsPropertySet(PartnerAccountPropertyType.ServicePrincipalSecret))
            {
                app = SharedTokenCacheClientFactory.CreateConfidentialClient(
                    $"{environment.ActiveDirectoryAuthority}{account.Tenant}",
                    account.GetProperty(PartnerAccountPropertyType.ApplicationId),
                    account.GetProperty(PartnerAccountPropertyType.ServicePrincipalSecret),
                    GetCertificate(account.GetProperty(PartnerAccountPropertyType.CertificateThumbprint)),
                    redirectUri,
                    account.Tenant);
            }
            else
            {
                app = SharedTokenCacheClientFactory.CreatePublicClient(
                    $"{environment.ActiveDirectoryAuthority}{account.Tenant}",
                    account.GetProperty(PartnerAccountPropertyType.ApplicationId),
                    redirectUri,
                    account.Tenant);
            }

            return(app);
        }
        /// <summary>
        /// Gets an aptly configured client.
        /// </summary>
        /// <param name="account">The account information to be used when generating the client.</param>
        /// <param name="environment">The environment where the client is connecting.</param>
        /// <param name="redirectUri">The redirect URI for the client.</param>
        /// <returns>An aptly configured client.</returns>
        public IClientApplicationBase GetClient(PartnerAccount account, PartnerEnvironment environment, string redirectUri = null)
        {
            IClientApplicationBase app;

            if (account.IsPropertySet(PartnerAccountPropertyType.CertificateThumbprint) || account.IsPropertySet(PartnerAccountPropertyType.ServicePrincipalSecret))
            {
                app = CreateConfidentialClient(
                    GetAzureCloudInstance(environment),
                    account.GetProperty(PartnerAccountPropertyType.ApplicationId),
                    account.GetProperty(PartnerAccountPropertyType.ServicePrincipalSecret),
                    GetCertificate(account.GetProperty(PartnerAccountPropertyType.CertificateThumbprint)),
                    redirectUri,
                    account.Tenant);
            }
            else
            {
                app = CreatePublicClient(
                    GetAzureCloudInstance(environment),
                    account.GetProperty(PartnerAccountPropertyType.ApplicationId),
                    redirectUri,
                    account.Tenant);
            }

            return(app);
        }