예제 #1
0
        protected AcquireTokenHandlerBase(RequestData requestData)
        {
            this.Authenticator = requestData.Authenticator;
            this.CallState     = CreateCallState(this.Authenticator.CorrelationId);
            PlatformPlugin.Logger.Information(this.CallState,
                                              string.Format(CultureInfo.CurrentCulture, "=== Token Acquisition started:\n\tAuthority: {0}\n\tResource: {1}\n\tClientId: {2}\n\tCacheType: {3}\n\tAuthentication Target: {4}\n\t",
                                                            requestData.Authenticator.Authority, requestData.Resource, requestData.ClientKey.ClientId,
                                                            (tokenCache != null) ? tokenCache.GetType().FullName + string.Format(CultureInfo.CurrentCulture, " ({0} items)", tokenCache.Count) : "null",
                                                            requestData.SubjectType));

            this.tokenCache = requestData.TokenCache;

            if (string.IsNullOrWhiteSpace(requestData.Resource))
            {
                throw new ArgumentNullException("resource");
            }

            this.Resource         = (requestData.Resource != NullResource) ? requestData.Resource : null;
            this.ClientKey        = requestData.ClientKey;
            this.TokenSubjectType = requestData.SubjectType;

            this.LoadFromCache = (tokenCache != null);
            this.StoreToCache  = (tokenCache != null);
            this.SupportADFS   = false;

            this.brokerParameters              = new Dictionary <string, string>();
            brokerParameters["authority"]      = requestData.Authenticator.Authority;
            brokerParameters["resource"]       = requestData.Resource;
            brokerParameters["client_id"]      = requestData.ClientKey.ClientId;
            brokerParameters["correlation_id"] = this.CallState.CorrelationId.ToString();
            brokerParameters["client_version"] = AdalIdHelper.GetAdalVersion();
            this.ResultEx = null;

            CacheQueryData.ExtendedLifeTimeEnabled = requestData.ExtendedLifeTimeEnabled;
        }
예제 #2
0
        public void AddAdalIdParameters(IDictionary <string, string> parameters)
        {
            parameters[AdalIdParameter.Product] = PlatformPlugin.PlatformInformation.GetProductName();
            parameters[AdalIdParameter.Version] = AdalIdHelper.GetAdalVersion();

            var processorInofrmation = PlatformPlugin.PlatformInformation.GetProcessorArchitecture();

            if (processorInofrmation != null)
            {
                parameters[AdalIdParameter.CpuPlatform] = processorInofrmation;
            }

            var osInformation = PlatformPlugin.PlatformInformation.GetOperatingSystem();

            if (osInformation != null)
            {
                parameters[AdalIdParameter.OS] = osInformation;
            }

            var deviceInformation = PlatformPlugin.PlatformInformation.GetDeviceModel();

            if (deviceInformation != null)
            {
                parameters[AdalIdParameter.DeviceModel] = deviceInformation;
            }
        }
예제 #3
0
        public void AddAdalIdParameters(IDictionary <string, string> parameters)
        {
            parameters[AdalIdParameter.Product] = PlatformSpecificHelper.GetProductName();
            parameters[AdalIdParameter.Version] = AdalIdHelper.GetAdalVersion();

#if !ADAL_WINPHONE
            parameters[AdalIdParameter.CpuPlatform] = AdalIdHelper.GetProcessorArchitecture();
#endif

#if ADAL_NET
            parameters[AdalIdParameter.OS] = Environment.OSVersion.ToString();
#endif
        }
        protected AcquireTokenHandlerBase(RequestData requestData)
        {
            this.Authenticator     = requestData.Authenticator;
            this.CallState         = CreateCallState(this.Authenticator.CorrelationId);
            brokerHelper.CallState = this.CallState;

            CallState.Logger.Information(null, string.Format(CultureInfo.CurrentCulture,
                                                             "ADAL {0} with assembly version '{1}', file version '{2}' and informational version '{3}' is running...",
                                                             platformInformation.GetProductName(), AdalIdHelper.GetAdalVersion(),
                                                             AdalIdHelper.GetAssemblyFileVersion(), AdalIdHelper.GetAssemblyInformationalVersion()));

            CallState.Logger.Information(this.CallState,
                                         string.Format(CultureInfo.CurrentCulture,
                                                       "=== Token Acquisition started:\n\tAuthority: {0}\n\tResource: {1}\n\tClientId: {2}\n\tCacheType: {3}\n\tAuthentication Target: {4}\n\t",
                                                       requestData.Authenticator.Authority, requestData.Resource, requestData.ClientKey.ClientId,
                                                       (tokenCache != null)
                        ? tokenCache.GetType().FullName +
                                                       string.Format(CultureInfo.CurrentCulture, " ({0} items)", tokenCache.Count)
                        : "null",
                                                       requestData.SubjectType));

            this.tokenCache = requestData.TokenCache;

            if (string.IsNullOrWhiteSpace(requestData.Resource))
            {
                throw new ArgumentNullException("resource");
            }

            this.Resource         = (requestData.Resource != NullResource) ? requestData.Resource : null;
            this.ClientKey        = requestData.ClientKey;
            this.TokenSubjectType = requestData.SubjectType;

            this.LoadFromCache = (tokenCache != null);
            this.StoreToCache  = (tokenCache != null);
            this.SupportADFS   = false;

            this.brokerParameters = new Dictionary <string, string>();
            brokerParameters[BrokerParameter.Authority]     = requestData.Authenticator.Authority;
            brokerParameters[BrokerParameter.Resource]      = requestData.Resource;
            brokerParameters[BrokerParameter.ClientId]      = requestData.ClientKey.ClientId;
            brokerParameters[BrokerParameter.CorrelationId] = this.CallState.CorrelationId.ToString();
            brokerParameters[BrokerParameter.ClientVersion] = AdalIdHelper.GetAdalVersion();
            this.ResultEx = null;

            CacheQueryData.ExtendedLifeTimeEnabled = requestData.ExtendedLifeTimeEnabled;
        }
        public void AddAdalIdParameters(IDictionary <string, string> parameters)
        {
            parameters[AdalIdParameter.Product] = PlatformSpecificHelper.GetProductName();
            parameters[AdalIdParameter.Version] = AdalIdHelper.GetAdalVersion();

#if !ADAL_WINPHONE
            parameters[AdalIdParameter.CpuPlatform] = AdalIdHelper.GetProcessorArchitecture();
#endif

#if ADAL_NET
            parameters[AdalIdParameter.OS] = Environment.OSVersion.ToString();

            // Since ADAL .NET may be used on servers, for security reasons, we do not emit device type.
#else
            // In WinRT, there is no way to reliably get OS version. All can be done reliably is to check
            // for existence of specific features which does not help in this case, so we do not emit OS in WinRT.

            var deviceInformation = new Windows.Security.ExchangeActiveSyncProvisioning.EasClientDeviceInformation();
            parameters[AdalIdParameter.DeviceModel] = deviceInformation.SystemProductName;
#endif
        }
 static AuthenticationContext()
 {
     PlatformPlugin.Logger.Information(null, string.Format("ADAL {0} with assembly version '{1}', file version '{2}' and informational version '{3}' is running...",
                                                           PlatformPlugin.PlatformInformation.GetProductName(), AdalIdHelper.GetAdalVersion(), AdalIdHelper.GetAssemblyFileVersion(), AdalIdHelper.GetAssemblyInformationalVersion()));
 }
        private static Assembly LoadPlatformSpecificAssembly()
        {
            // For security reasons, it is important to have PublicKeyToken mentioned referencing the assembly.
            const string PlatformSpecificAssemblyNameTemplate = "Microsoft.IdentityModel.Clients.ActiveDirectory.Platform, Version={0}, Culture=neutral, PublicKeyToken=31bf3856ad364e35";

            string platformSpecificAssemblyName = string.Format(CultureInfo.CurrentCulture, PlatformSpecificAssemblyNameTemplate, AdalIdHelper.GetAdalVersion());

            try
            {
                return(Assembly.Load(new AssemblyName(platformSpecificAssemblyName)));
            }
            catch (FileNotFoundException ex)
            {
                throw new AdalException(AdalError.AssemblyNotFound, string.Format(CultureInfo.InvariantCulture, AdalErrorMessage.AssemblyNotFoundTemplate, platformSpecificAssemblyName), ex);
            }
            catch (Exception ex) // FileLoadException is missing from PCL
            {
                throw new AdalException(AdalError.AssemblyLoadFailed, string.Format(CultureInfo.InvariantCulture, AdalErrorMessage.AssemblyLoadFailedTemplate, platformSpecificAssemblyName), ex);
            }
        }
        private static void InitializeFactoryMethod()
        {
            if (null != dialogFactory)
            {
                return;
            }

            const string WebAuthenticationDialogClassName = "Microsoft.IdentityModel.Clients.ActiveDirectory.Internal.BrowserDialogFactory";
            const string FactoryMethodName = "CreateAuthenticationDialog";

            string webAuthenticationDialogAssemblyName = string.Format(WebAuthenticationDialogAssemblyNameTemplate, AdalIdHelper.GetAdalVersion());

            try
            {
                Assembly webAuthenticationDialogAssembly = Assembly.Load(webAuthenticationDialogAssemblyName);
                Type     dialogFactoryType = webAuthenticationDialogAssembly.GetType(WebAuthenticationDialogClassName);
                dialogFactory = dialogFactoryType.GetMethod(FactoryMethodName, BindingFlags.Static | BindingFlags.NonPublic);
            }
            catch (FileNotFoundException ex)
            {
                ThrowAssemlyLoadFailedException(webAuthenticationDialogAssemblyName, ex);
            }
            catch (FileLoadException ex)
            {
                ThrowAssemlyLoadFailedException(webAuthenticationDialogAssemblyName, ex);
            }
        }