protected BaseRequest(AuthenticationRequestParameters authenticationRequestParameters)
        {
            this.Authenticator = authenticationRequestParameters.Authenticator;
            this.CallState     = CreateCallState(this.Authenticator.CorrelationId);

            PlatformPlugin.Logger.Information(this.CallState,
                                              string.Format(CultureInfo.InvariantCulture, "=== Token Acquisition started:\n\tAuthority: {0}\n\tScope: {1}\n\tClientId: {2}\n\tCacheType: {3}",
                                                            Authenticator.Authority, authenticationRequestParameters.Scope.AsSingleString(), authenticationRequestParameters.ClientKey.ClientId,
                                                            (tokenCache != null) ? tokenCache.GetType().FullName + string.Format(CultureInfo.InvariantCulture, " ({0} items)", tokenCache.Count) : "null"));

            this.tokenCache           = authenticationRequestParameters.TokenCache;
            this.ClientKey            = authenticationRequestParameters.ClientKey;
            this.Policy               = authenticationRequestParameters.Policy;
            this.restrictToSingleUser = authenticationRequestParameters.RestrictToSingleUser;

            if (MsalStringHelper.IsNullOrEmpty(authenticationRequestParameters.Scope))
            {
                throw new ArgumentNullException("scope");
            }

            this.Scope = authenticationRequestParameters.Scope.CreateSetFromArray();
            ValidateScopeInput(this.Scope);


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

            if (this.tokenCache != null && (restrictToSingleUser && this.tokenCache.GetUniqueIdsFromCache(this.ClientKey.ClientId).Count() > 1))
            {
                throw new ArgumentException(
                          "Cache cannot have entries for more than 1 unique id when RestrictToSingleUser is set to TRUE.");
            }
        }
Esempio n. 2
0
        public AcquireTokenInteractiveHandler(HandlerData handlerData,
                                              string[] additionalScope, Uri redirectUri, IPlatformParameters parameters, string loginHint, UiOptions?uiOptions, string extraQueryParameters, IWebUI webUI)
            : base(handlerData)
        {
            this._redirectUri = PlatformPlugin.PlatformInformation.ValidateRedirectUri(redirectUri, this.CallState);

            if (!string.IsNullOrWhiteSpace(this._redirectUri.Fragment))
            {
                throw new ArgumentException(MsalErrorMessage.RedirectUriContainsFragment, "redirectUri");
            }

            _additionalScope = new HashSet <string>();
            if (!MsalStringHelper.IsNullOrEmpty(additionalScope))
            {
                this._additionalScope = additionalScope.CreateSetFromArray();
            }

            ValidateScopeInput(this._additionalScope);

            this._authorizationParameters     = parameters;
            this._redirectUriRequestParameter = PlatformPlugin.PlatformInformation.GetRedirectUriAsString(this._redirectUri, this.CallState);


            this._loginHint = loginHint;
            if (!string.IsNullOrWhiteSpace(extraQueryParameters) && extraQueryParameters[0] == '&')
            {
                extraQueryParameters = extraQueryParameters.Substring(1);
            }

            this._extraQueryParameters = extraQueryParameters;
            this._webUi        = webUI;
            this._uiOptions    = uiOptions;
            this.LoadFromCache = false; //no cache lookup and refresh for interactive.
            this.SupportADFS   = false;

            if (string.IsNullOrWhiteSpace(loginHint) && _uiOptions == UiOptions.ActAsCurrentUser)
            {
                throw new ArgumentException(MsalErrorMessage.LoginHintNullForUiOption, "loginHint");
            }

            PlatformPlugin.BrokerHelper.PlatformParameters = _authorizationParameters;
        }