Exemplo n.º 1
0
        public AuthenticationRequestParameters(
            IServiceBundle serviceBundle,
            AcquireTokenCommonParameters commonParameters,
            RequestContext requestContext)
        {
            _commonParameters = commonParameters;

            Authority = commonParameters.AuthorityOverride == null
                ? serviceBundle.Config.Authority
                : commonParameters.AuthorityOverride;

            ClientId       = serviceBundle.Config.ClientId;
            Scope          = ScopeHelper.CreateSortedSetFromEnumerable(commonParameters.Scopes);
            RedirectUri    = serviceBundle.Config.RedirectUri;
            RequestContext = requestContext;

            // Set application wide query parameters.
            ExtraQueryParameters = serviceBundle.Config.ExtraQueryParameters ?? new Dictionary <string, string>();

            // Copy in call-specific query parameters.
            if (commonParameters.ExtraQueryParameters != null)
            {
                foreach (var kvp in commonParameters.ExtraQueryParameters)
                {
                    ExtraQueryParameters[kvp.Key] = kvp.Value;
                }
            }
        }
        internal AuthenticationResult(OAuth2TokenResponse tokenResponse, bool isExtendedLifetimeEnabled)
        {
            IdToken idToken = Auth.IdToken.Parse(tokenResponse.IdToken);

            bool isExtendedLifetimeToken = isExtendedLifetimeEnabled && tokenResponse.AccessTokenExtendedExpiresOn >
                                           DateTime.UtcNow + TimeSpan.FromMinutes(DefaultExpirationBufferInMinutes);

            var scopes = ScopeHelper.ConvertStringToLowercaseSortedSet(tokenResponse.Scope);

            AccessToken             = tokenResponse.AccessToken;
            IsExtendedLifeTimeToken = isExtendedLifetimeToken;
            UniqueId          = idToken.GetUniqueId();
            ExpiresOn         = tokenResponse.AccessTokenExpiresOn;
            ExtendedExpiresOn = tokenResponse.AccessTokenExtendedExpiresOn;
            IdToken           = tokenResponse.IdToken;
            Scopes            = scopes;
        }
        public InteractiveRequest(
            IServiceBundle serviceBundle,
            AuthenticationRequestParameters authenticationRequestParameters,
            AcquireTokenInteractiveParameters interactiveParameters,
            IWebUI webUi)
            : base(serviceBundle, authenticationRequestParameters, interactiveParameters)
        {
            _interactiveParameters = interactiveParameters;
            RedirectUriHelper.Validate(authenticationRequestParameters.RedirectUri);
            webUi?.ValidateRedirectUri(authenticationRequestParameters.RedirectUri);

            // todo(migration): can't this just come directly from interactive parameters instead of needing do to this?
            _extraScopesToConsent = new SortedSet <string>();
            if (!_interactiveParameters.ExtraScopesToConsent.IsNullOrEmpty())
            {
                _extraScopesToConsent = ScopeHelper.CreateSortedSetFromEnumerable(_interactiveParameters.ExtraScopesToConsent);
            }

            ValidateScopeInput(_extraScopesToConsent);

            _webUi = webUi;
            _interactiveParameters.LogParameters(authenticationRequestParameters.RequestContext.Logger);
        }