コード例 #1
0
        private Task <IAuthenticationResult> AuthenticateUsingCertificate(AdalServiceInfo adalServiceInfo, string refreshToken)
        {
            var clientAssertionCertificate = new ClientAssertionCertificate(adalServiceInfo.AppId, adalServiceInfo.ClientCertificate);

            return(this.authenticationContextWrapper.AcquireTokenByRefreshTokenAsync(
                       refreshToken,
                       clientAssertionCertificate,
                       adalServiceInfo.ServiceResource));
        }
コード例 #2
0
        public override void Setup()
        {
            base.Setup();

            this.adalServiceInfo = new AdalServiceInfo();
            this.adalServiceInfo.CopyFrom(this.serviceInfo);

            this.authenticationProvider = new AdalAuthenticationProvider(this.adalServiceInfo);
        }
        /// <summary>
        /// Generates the <see cref="ServiceInfo"/> for the current application configuration.
        /// </summary>
        /// <param name="appConfig">The <see cref="AppConfig"/> for the current application.</param>
        /// <param name="credentialCache">The cache instance for storing user credentials.</param>
        /// <param name="httpProvider">The <see cref="IHttpProvider"/> for sending HTTP requests.</param>
        /// <param name="clientType">The <see cref="ClientType"/> to specify the business or consumer service.</param>
        /// <returns>The <see cref="ServiceInfo"/> for the current session.</returns>
        public async override Task <ServiceInfo> GetServiceInfo(
            AppConfig appConfig,
            CredentialCache credentialCache,
            IHttpProvider httpProvider,
            ClientType clientType = ClientType.Business)
        {
            if (clientType == ClientType.Consumer)
            {
                throw new OneDriveException(
                          new Error
                {
                    Code    = OneDriveErrorCode.AuthenticationFailure.ToString(),
                    Message = "AdalAuthenticationByCodeServiceInfoProvider only supports Active Directory authentication."
                });
            }

            if (string.IsNullOrEmpty(appConfig.ActiveDirectoryServiceResource))
            {
                throw new OneDriveException(
                          new Error
                {
                    Code    = OneDriveErrorCode.AuthenticationFailure.ToString(),
                    Message = "Service resource ID is required for authentication by code.",
                });
            }

            var serviceInfo = await base.GetServiceInfo(appConfig, credentialCache, httpProvider, clientType);

            var adalServiceInfo = new AdalServiceInfo();

            adalServiceInfo.CopyFrom(serviceInfo);

            var adalAppConfig = appConfig as BusinessAppConfig;

            if (adalAppConfig != null)
            {
                adalServiceInfo.ClientCertificate = adalAppConfig.ActiveDirectoryClientCertificate;
            }

            if (string.IsNullOrEmpty(adalServiceInfo.BaseUrl) && !string.IsNullOrEmpty(adalServiceInfo.ServiceResource))
            {
                adalServiceInfo.BaseUrl = string.Format(
                    Constants.Authentication.OneDriveBusinessBaseUrlFormatString,
                    adalServiceInfo.ServiceResource.TrimEnd('/'),
                    "v2.0");
            }

            if (adalServiceInfo.AuthenticationProvider == null)
            {
                adalServiceInfo.AuthenticationProvider = new AdalAuthenticationByCodeAuthenticationProvider(adalServiceInfo, authorizationCode);
            }

            return(adalServiceInfo);
        }
コード例 #4
0
        private Task <IAuthenticationResult> AuthenticateUsingCertificate(AdalServiceInfo adalServiceInfo, string resource)
        {
            var returnUri = new Uri(this.ServiceInfo.ReturnUrl);

            var clientAssertionCertificate = new ClientAssertionCertificate(adalServiceInfo.AppId, adalServiceInfo.ClientCertificate);

            return(this.authenticationContextWrapper.AcquireTokenByAuthorizationCodeAsync(
                       this.authenticationCode,
                       returnUri,
                       clientAssertionCertificate,
                       resource));
        }
        public override void Setup()
        {
            base.Setup();

            this.adalServiceInfo = new AdalServiceInfo();
            this.adalServiceInfo.CopyFrom(this.serviceInfo);

            this.authenticationProvider = new TestAdalAuthenticationByCodeAuthenticationProvider(this.adalServiceInfo, authenticationCode);

            this.authenticationContextWrapper = new MockAuthenticationContextWrapper();
            this.authenticationProvider.authenticationContextWrapper = this.authenticationContextWrapper.Object;
        }
        public override void Setup()
        {
            base.Setup();

            this.adalServiceInfo = new AdalServiceInfo();
            this.adalServiceInfo.CopyFrom(this.serviceInfo);

            this.authenticationProvider = new TestAdalAppOnlyAuthenticationProvider(this.adalServiceInfo);

            this.authenticationContextWrapper = new MockAuthenticationContextWrapper();
            this.authenticationProvider.authenticationContextWrapper = this.authenticationContextWrapper.Object;

            this.clientCertificate = new X509Certificate2(@"Certs\testwebapplication.pfx", "password");
            this.adalServiceInfo.ClientCertificate = this.clientCertificate;
        }
コード例 #7
0
        public async override Task<ServiceInfo> GetServiceInfo(
            AppConfig appConfig,
            CredentialCache credentialCache,
            IHttpProvider httpProvider,
            ClientType clientType = ClientType.Business)
        {
            if (clientType == ClientType.Consumer)
            {
                throw new OneDriveException(
                    new Error
                    {
                        Code = OneDriveErrorCode.AuthenticationFailure.ToString(),
                        Message = "AdalServiceInfoProvider only supports Active Directory authentication."
                    });
            }

            var serviceInfo = await base.GetServiceInfo(appConfig, credentialCache, httpProvider, clientType);

            var adalServiceInfo = new AdalServiceInfo();
            adalServiceInfo.CopyFrom(serviceInfo);

            if (string.IsNullOrEmpty(adalServiceInfo.BaseUrl) && !string.IsNullOrEmpty(adalServiceInfo.ServiceResource))
            {
                adalServiceInfo.BaseUrl = string.Format(
                    Constants.Authentication.OneDriveBusinessBaseUrlFormatString,
                    adalServiceInfo.ServiceResource.TrimEnd('/'),
                    "v2.0");
            }

            var adalAppConfig = appConfig as BusinessAppConfig;

            if (adalAppConfig != null)
            {
                adalServiceInfo.ClientCertificate = adalAppConfig.ActiveDirectoryClientCertificate;
            }

            if (adalServiceInfo.AuthenticationProvider == null)
            {
                adalServiceInfo.AuthenticationProvider = new AdalAuthenticationProvider(adalServiceInfo);
            }

            return adalServiceInfo;
        }
 /// <summary>
 /// Constructs an <see cref="TestAdalAppOnlyAuthenticationProvider"/>.
 /// </summary>
 /// <param name="serviceInfo">The information for authenticating against the service.</param>
 /// <param name="currentAccountSession">The current account session, used for initializing an already logged in application.</param>
 public TestAdalAppOnlyAuthenticationProvider(AdalServiceInfo serviceInfo)
     : base(serviceInfo)
 {
 }
コード例 #9
0
 /// <summary>
 /// Constructs an <see cref="AdalAppOnlyAuthenticationProvider"/>.
 /// </summary>
 /// <param name="serviceInfo">The information for authenticating against the service.</param>
 public AdalAppOnlyAuthenticationProvider(AdalServiceInfo serviceInfo)
     : base(serviceInfo, currentAccountSession: null)
 {
     this.allowDiscoveryService = false;
 }
        private Task<IAuthenticationResult> AuthenticateUsingCertificate(AdalServiceInfo adalServiceInfo, string resource)
        {
            var returnUri = new Uri(this.ServiceInfo.ReturnUrl);

            var clientAssertionCertificate = new ClientAssertionCertificate(adalServiceInfo.AppId, adalServiceInfo.ClientCertificate);

            return this.authenticationContextWrapper.AcquireTokenByAuthorizationCodeAsync(
                this.authenticationCode,
                returnUri,
                clientAssertionCertificate,
                resource);
        }
 /// <summary>
 /// Constructs an <see cref="TestAdalAuthenticationByCodeAuthenticationProvider"/>.
 /// </summary>
 /// <param name="serviceInfo">The information for authenticating against the service.</param>
 /// <param name="authenticationCode">The code for retrieving the authentication token.</param>
 /// <param name="currentAccountSession">The current account session, used for initializing an already logged in application.</param>
 public TestAdalAuthenticationByCodeAuthenticationProvider(AdalServiceInfo serviceInfo, string authenticationCode)
     : base(serviceInfo, authenticationCode)
 {
 }
 /// <summary>
 /// Constructs an <see cref="AdalAppOnlyAuthenticationProvider"/>.
 /// </summary>
 /// <param name="serviceInfo">The information for authenticating against the service.</param>
 public AdalAppOnlyAuthenticationProvider(AdalServiceInfo serviceInfo)
     : base(serviceInfo, currentAccountSession: null)
 {
     this.allowDiscoveryService = false;
 }
コード例 #13
0
        private Task<IAuthenticationResult> AuthenticateUsingCertificate(AdalServiceInfo adalServiceInfo, string refreshToken)
        {
            var clientAssertionCertificate = new ClientAssertionCertificate(adalServiceInfo.AppId, adalServiceInfo.ClientCertificate);

            return this.authenticationContextWrapper.AcquireTokenByRefreshTokenAsync(
                refreshToken,
                clientAssertionCertificate,
                adalServiceInfo.ServiceResource);
        }