public InteractiveRequest(AuthenticationRequestParameters authenticationRequestParameters, string[] additionalScope, UiOptions uiOptions, IWebUI webUI) : this( authenticationRequestParameters, additionalScope, authenticationRequestParameters.User?.DisplayableId, uiOptions, webUI) { }
public static void ConfigureMockWebUI(IPlatformProxy platformProxy, IWebUI webUi = null) { IWebUIFactory mockFactory = Substitute.For <IWebUIFactory>(); mockFactory.CreateAuthenticationDialog(Arg.Any <CoreUIParent>(), Arg.Any <RequestContext>()).Returns(webUi); platformProxy.SetWebUiFactory(mockFactory); }
private async Task <Tuple <AuthorizationResult, string> > FetchAuthCodeAndPkceInternalAsync( IWebUI webUi, CancellationToken cancellationToken) { RedirectUriHelper.Validate(_requestParams.RedirectUri); _requestParams.RedirectUri = webUi.UpdateRedirectUri(_requestParams.RedirectUri); Tuple <Uri, string, string> authorizationTuple = CreateAuthorizationUri(true); Uri authorizationUri = authorizationTuple.Item1; string state = authorizationTuple.Item2; string codeVerifier = authorizationTuple.Item3; var uiEvent = new UiEvent(_requestParams.RequestContext.CorrelationId.AsMatsCorrelationId()); using (_requestParams.RequestContext.CreateTelemetryHelper(uiEvent)) { var authorizationResult = await webUi.AcquireAuthorizationAsync( authorizationUri, _requestParams.RedirectUri, _requestParams.RequestContext, cancellationToken).ConfigureAwait(false); uiEvent.UserCancelled = authorizationResult.Status == AuthorizationStatus.UserCancel; uiEvent.AccessDenied = authorizationResult.Status == AuthorizationStatus.ProtocolError; VerifyAuthorizationResult(authorizationResult, state); return(new Tuple <AuthorizationResult, string>(authorizationResult, codeVerifier)); } }
public InteractiveRequest(AuthenticationRequestParameters authenticationRequestParameters, IEnumerable <string> extraScopesToConsent, string loginHint, UIBehavior UIBehavior, IWebUI webUI) : base(authenticationRequestParameters) { PlatformPlugin.PlatformInformation.ValidateRedirectUri(authenticationRequestParameters.RedirectUri, authenticationRequestParameters.RequestContext); if (!string.IsNullOrWhiteSpace(authenticationRequestParameters.RedirectUri.Fragment)) { throw new ArgumentException(MsalErrorMessage.RedirectUriContainsFragment, nameof(authenticationRequestParameters.RedirectUri)); } _extraScopesToConsent = new SortedSet <string>(); if (!MsalHelpers.IsNullOrEmpty(extraScopesToConsent)) { _extraScopesToConsent = extraScopesToConsent.CreateSetFromEnumerable(); } ValidateScopeInput(_extraScopesToConsent); authenticationRequestParameters.LoginHint = loginHint; if (!string.IsNullOrWhiteSpace(authenticationRequestParameters.ExtraQueryParameters) && authenticationRequestParameters.ExtraQueryParameters[0] == '&') { authenticationRequestParameters.ExtraQueryParameters = authenticationRequestParameters.ExtraQueryParameters.Substring(1); } _webUi = webUI; _UIBehavior = UIBehavior; LoadFromCache = false; //no cache lookup and refresh for interactive. AuthenticationRequestParameters.RequestContext.Logger.Info("Additional scopes - " + _extraScopesToConsent.AsSingleString() + ";" + "UIBehavior - " + _UIBehavior.PromptValue); }
public InteractiveRequest( IServiceBundle serviceBundle, AuthenticationRequestParameters authenticationRequestParameters, ApiEvent.ApiIds apiId, IEnumerable <string> extraScopesToConsent, string loginHint, UIBehavior uiBehavior, IWebUI webUi) : base(serviceBundle, authenticationRequestParameters, apiId) { RedirectUriHelper.Validate(authenticationRequestParameters.RedirectUri); webUi?.ValidateRedirectUri(authenticationRequestParameters.RedirectUri); _extraScopesToConsent = new SortedSet <string>(); if (!extraScopesToConsent.IsNullOrEmpty()) { _extraScopesToConsent = ScopeHelper.CreateSortedSetFromEnumerable(extraScopesToConsent); } ValidateScopeInput(_extraScopesToConsent); authenticationRequestParameters.LoginHint = loginHint; if (!string.IsNullOrWhiteSpace(authenticationRequestParameters.ExtraQueryParameters) && authenticationRequestParameters.ExtraQueryParameters[0] == '&') { authenticationRequestParameters.ExtraQueryParameters = authenticationRequestParameters.ExtraQueryParameters.Substring(1); } _webUi = webUi; _uiBehavior = uiBehavior; AuthenticationRequestParameters.RequestContext.Logger.Info( "Additional scopes - " + _extraScopesToConsent.AsSingleString() + ";" + "UIBehavior - " + _uiBehavior.PromptValue); }
private void AcquireTokenAndContinueCommon(string resource, string clientId, Uri redirectUri, UserIdentifier userId, string extraQueryParameters, AuthenticationContextDelegate authDelegate) { IWebUI webUi = this.CreateWebAuthenticationDialog(); var handler = new AcquireTokenInteractiveHandler(this.Authenticator, this.TokenCache, resource, clientId, redirectUri, webUi.PromptBehavior, userId, extraQueryParameters, webUi, false); handler.AcquireAuthorization(); this.authenticationContextDelegate = authDelegate; }
public IWebUI Create(PromptBehavior promptBehavior, object ownerWindow) { InitializeFactoryMethod(); object[] parameters = { promptBehavior }; IWebUI dialog = (IWebUI)dialogFactory.Invoke(null, parameters); dialog.OwnerWindow = ownerWindow; return(dialog); }
private static void ConfigureWebUiFactory(IServiceBundle serviceBundle, IWebUI webUi) { IWebUIFactory mockFactory = Substitute.For <IWebUIFactory>(); mockFactory.CreateAuthenticationDialog( Arg.Any <CoreUIParent>(), Arg.Any <WebViewPreference>(), Arg.Any <RequestContext>()).Returns(webUi); serviceBundle.Config.WebUiFactoryCreator = () => mockFactory; }
public NonInteractiveRegisterAccountRequest( IServiceBundle serviceBundle, AuthenticationRequestParameters authenticationRequestParameters, ApiEvent.ApiIds apiId, IEnumerable <string> extraScopesToConsent, string loginHint, UIBehavior uiBehavior, IWebUI webUi, string email) : base(serviceBundle, authenticationRequestParameters, apiId, extraScopesToConsent, loginHint, uiBehavior, webUi) { Init(email); }
public AcquireTokenInteractiveHandler(Authenticator authenticator, TokenCache tokenCache, string resource, string clientId, Uri redirectUri, IPlatformParameters parameters, UserIdentifier userId, string extraQueryParameters, IWebUI webUI) : base(authenticator, tokenCache, resource, new ClientKey(clientId), TokenSubjectType.User) { this.redirectUri = PlatformPlugin.PlatformInformation.ValidateRedirectUri(redirectUri, this.CallState); if (!string.IsNullOrWhiteSpace(this.redirectUri.Fragment)) { throw new ArgumentException(AdalErrorMessage.RedirectUriContainsFragment, "redirectUri"); } this.authorizationParameters = parameters; this.redirectUriRequestParameter = PlatformPlugin.PlatformInformation.GetRedirectUriAsString(this.redirectUri, this.CallState); if (userId == null) { throw new ArgumentNullException("userId", AdalErrorMessage.SpecifyAnyUser); } this.userId = userId; if (!string.IsNullOrEmpty(extraQueryParameters) && extraQueryParameters[0] == '&') { extraQueryParameters = extraQueryParameters.Substring(1); } this.extraQueryParameters = extraQueryParameters; this.webUi = webUI; this.UniqueId = userId.UniqueId; this.DisplayableId = userId.DisplayableId; this.UserIdentifierType = userId.Type; this.LoadFromCache = (tokenCache != null && parameters != null && PlatformPlugin.PlatformInformation.GetCacheLoadPolicy(parameters)); this.SupportADFS = true; this.CacheQueryData.DisplayableId = this.DisplayableId; this.CacheQueryData.UniqueId = this.UniqueId; this.brokerParameters["force"] = "NO"; if (userId != UserIdentifier.AnyUser) { this.brokerParameters["username"] = userId.Id; } else { this.brokerParameters["username"] = string.Empty; } this.brokerParameters["username_type"] = userId.Type.ToString(); this.brokerParameters["redirect_uri"] = redirectUri.AbsoluteUri; this.brokerParameters["extra_qp"] = extraQueryParameters; PlatformPlugin.BrokerHelper.PlatformParameters = authorizationParameters; }
public NonInteractiveLoginRequest( IServiceBundle serviceBundle, AuthenticationRequestParameters authenticationRequestParameters, ApiEvent.ApiIds apiId, IEnumerable <string> extraScopesToConsent, string loginHint, UIBehavior uiBehavior, IWebUI webUi, string userName, string password) : base(serviceBundle, authenticationRequestParameters, apiId, extraScopesToConsent, loginHint, uiBehavior, webUi) { Init(userName, password); }
/// <summary> /// Configures a web ui that returns a succesfull result /// </summary> public static void ConfigureMockWebUI( this IServiceBundle serviceBundle, IWebUI webUi = null) { if (webUi == null) { webUi = new MockWebUI { MockResult = AuthorizationResult.FromUri(serviceBundle.Config.RedirectUri + "?code=some-code") }; } ConfigureWebUiFactory(serviceBundle, webUi); }
public AcquireTokenInteractiveHandler(Authenticator authenticator, TokenCache tokenCache, string resource, string clientId, Uri redirectUri, PromptBehavior promptBehavior, UserIdentifier userId, string extraQueryParameters, IWebUI webUI, bool callSync) : base(authenticator, tokenCache, resource, new ClientKey(clientId), TokenSubjectType.User, callSync) { if (redirectUri == null) { throw new ArgumentNullException("redirectUri"); } if (!string.IsNullOrWhiteSpace(redirectUri.Fragment)) { var ex = new ArgumentException(AdalErrorMessage.RedirectUriContainsFragment, "redirectUri"); Logger.LogException(this.CallState, ex); throw ex; } this.redirectUri = redirectUri; this.SetRedirectUriRequestParameter(); if (userId == null) { var ex = new ArgumentNullException("userId", AdalErrorMessage.SpecifyAnyUser); Logger.LogException(this.CallState, ex); throw ex; } this.userId = userId; this.promptBehavior = promptBehavior; if (!string.IsNullOrEmpty(extraQueryParameters) && extraQueryParameters[0] == '&') { extraQueryParameters = extraQueryParameters.Substring(1); } this.extraQueryParameters = extraQueryParameters; this.webUi = webUI; this.UniqueId = userId.UniqueId; this.DisplayableId = userId.DisplayableId; this.UserIdentifierType = userId.Type; this.LoadFromCache = (tokenCache != null && this.promptBehavior != PromptBehavior.Always && this.promptBehavior != PromptBehavior.RefreshSession); this.SupportADFS = true; }
public InteractiveRequest( IServiceBundle serviceBundle, AuthenticationRequestParameters authenticationRequestParameters, ApiEvent.ApiIds apiId, IEnumerable <string> extraScopesToConsent, UIBehavior uiBehavior, IWebUI webUi) : this( serviceBundle, authenticationRequestParameters, apiId, extraScopesToConsent, authenticationRequestParameters.Account?.Username, uiBehavior, webUi) { }
public AcquireTokenInteractiveHandler(Authenticator authenticator, TokenCache tokenCache, string[] scope, string[] additionalScope, string clientId, Uri redirectUri, IPlatformParameters parameters, UserIdentifier userId, string extraQueryParameters, IWebUI webUI) : base(authenticator, tokenCache, scope, new ClientKey(clientId), TokenSubjectType.User) { this.redirectUri = PlatformPlugin.PlatformInformation.ValidateRedirectUri(redirectUri, this.CallState); if (!string.IsNullOrWhiteSpace(this.redirectUri.Fragment)) { throw new ArgumentException(AdalErrorMessage.RedirectUriContainsFragment, "redirectUri"); } this.authorizationParameters = parameters; if (!ADALScopeHelper.IsNullOrEmpty(additionalScope)) { this.additionalScope = additionalScope; } else { this.additionalScope = new string[] {}; } ValidateScopeInput(scope.Union(this.additionalScope).ToArray()); this.redirectUriRequestParameter = PlatformPlugin.PlatformInformation.GetRedirectUriAsString(this.redirectUri, this.CallState); if (userId == null) { throw new ArgumentNullException("userId", AdalErrorMessage.SpecifyAnyUser); } this.userId = userId; if (!string.IsNullOrEmpty(extraQueryParameters) && extraQueryParameters[0] == '&') { extraQueryParameters = extraQueryParameters.Substring(1); } this.extraQueryParameters = extraQueryParameters; this.webUi = webUI; this.UniqueId = userId.UniqueId; this.DisplayableId = userId.DisplayableId; this.UserIdentifierType = userId.Type; this.LoadFromCache = (tokenCache != null && parameters != null && PlatformPlugin.PlatformInformation.GetCacheLoadPolicy(parameters)); this.SupportADFS = false; }
public AcquireTokenInteractiveHandler(Authenticator authenticator, TokenCache tokenCache, string resource, string clientId, Uri redirectUri, PromptBehavior promptBehavior, UserIdentifier userId, string extraQueryParameters, IWebUI webUI, bool callSync) : base(authenticator, tokenCache, resource, new ClientKey(clientId), TokenSubjectType.User, callSync) { if (redirectUri == null) { throw new ArgumentNullException("redirectUri"); } if (!string.IsNullOrWhiteSpace(redirectUri.Fragment)) { throw new ArgumentException(AdalErrorMessage.RedirectUriContainsFragment, "redirectUri"); } this.redirectUri = redirectUri; this.SetRedirectUriRequestParameter(); if (userId == null) { throw new ArgumentNullException("userId", AdalErrorMessage.SpecifyAnyUser); } this.userId = userId; this.promptBehavior = promptBehavior; if (!string.IsNullOrEmpty(extraQueryParameters) && extraQueryParameters[0] == '&') { extraQueryParameters = extraQueryParameters.Substring(1); } this.extraQueryParameters = extraQueryParameters; this.webUi = webUI; this.UniqueId = userId.UniqueId; this.DisplayableId = userId.DisplayableId; this.UserIdentifierType = userId.Type; this.LoadFromCache = (tokenCache != null && this.promptBehavior != PromptBehavior.Always && this.promptBehavior != PromptBehavior.RefreshSession); this.SupportADFS = true; }
public InteractiveRequest(AuthenticationRequestParameters authenticationRequestParameters, string[] additionalScope, Uri redirectUri, IPlatformParameters parameters, string loginHint, UiOptions? uiOptions, string extraQueryParameters, IWebUI webUI) : base(authenticationRequestParameters) { 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; }
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; }
public AcquireTokenInteractiveHandler(Authenticator authenticator, TokenCache tokenCache, string resource, string clientId, Uri redirectUri, IAuthorizationParameters parameters, UserIdentifier userId, string extraQueryParameters, IWebUI webUI, bool callSync) : base(authenticator, tokenCache, resource, new ClientKey(clientId), TokenSubjectType.User, callSync) { this.redirectUri = PlatformPlugin.PlatformInformation.ValidateRedirectUri(redirectUri, this.CallState); if (!string.IsNullOrWhiteSpace(this.redirectUri.Fragment)) { var ex = new ArgumentException(AdalErrorMessage.RedirectUriContainsFragment, "redirectUri"); PlatformPlugin.Logger.LogException(this.CallState, ex); throw ex; } this.authorizationParameters = parameters; this.redirectUriRequestParameter = PlatformPlugin.PlatformInformation.GetRedirectUriAsString(this.redirectUri, this.CallState); if (userId == null) { var ex = new ArgumentNullException("userId", AdalErrorMessage.SpecifyAnyUser); PlatformPlugin.Logger.LogException(this.CallState, ex); throw ex; } this.userId = userId; if (!string.IsNullOrEmpty(extraQueryParameters) && extraQueryParameters[0] == '&') { extraQueryParameters = extraQueryParameters.Substring(1); } this.extraQueryParameters = extraQueryParameters; this.webUi = webUI; this.UniqueId = userId.UniqueId; this.DisplayableId = userId.DisplayableId; this.UserIdentifierType = userId.Type; this.LoadFromCache = (tokenCache != null && parameters != null && PlatformPlugin.PlatformInformation.GetCacheLoadPolicy(parameters)); this.SupportADFS = true; }
public InteractiveRequest(AuthenticationRequestParameters authenticationRequestParameters, string[] additionalScope, string loginHint, UiOptions?uiOptions, IWebUI webUI) : base(authenticationRequestParameters) { PlatformPlugin.PlatformInformation.ValidateRedirectUri(authenticationRequestParameters.RedirectUri, this.CallState); if (!string.IsNullOrWhiteSpace(authenticationRequestParameters.RedirectUri.Fragment)) { throw new ArgumentException(MsalErrorMessage.RedirectUriContainsFragment, "redirectUri"); } _additionalScope = new SortedSet <string>(); if (!MsalHelpers.IsNullOrEmpty(additionalScope)) { this._additionalScope = additionalScope.CreateSetFromArray(); } ValidateScopeInput(this._additionalScope); authenticationRequestParameters.LoginHint = loginHint; if (!string.IsNullOrWhiteSpace(authenticationRequestParameters.ExtraQueryParameters) && authenticationRequestParameters.ExtraQueryParameters[0] == '&') { authenticationRequestParameters.ExtraQueryParameters = authenticationRequestParameters.ExtraQueryParameters.Substring(1); } this._webUi = webUI; this._uiOptions = uiOptions; this.LoadFromCache = false; //no cache lookup and refresh for interactive. if (string.IsNullOrWhiteSpace(loginHint) && _uiOptions == UiOptions.ActAsCurrentUser) { throw new ArgumentException(MsalErrorMessage.LoginHintNullForUiOption, "loginHint"); } PlatformPlugin.BrokerHelper.PlatformParameters = authenticationRequestParameters.PlatformParameters; }
public InteractiveRequest( IServiceBundle serviceBundle, AuthenticationRequestParameters authenticationRequestParameters, AcquireTokenInteractiveParameters interactiveParameters, IWebUI webUi) : base(serviceBundle, authenticationRequestParameters, interactiveParameters) { _webUi = webUi; // can be null just to generate the authorization uri _interactiveParameters = interactiveParameters; RedirectUriHelper.Validate(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); _interactiveParameters.LogParameters(authenticationRequestParameters.RequestContext.Logger); }
private async Task <Tuple <AuthorizationResult, string> > FetchAuthCodeAndPkceInternalAsync( IWebUI webUi, CancellationToken cancellationToken) { RedirectUriHelper.Validate(_requestParams.RedirectUri); _requestParams.RedirectUri = webUi.UpdateRedirectUri(_requestParams.RedirectUri); Tuple <Uri, string, string> authorizationTuple = CreateAuthorizationUri(true); Uri authorizationUri = authorizationTuple.Item1; string state = authorizationTuple.Item2; string codeVerifier = authorizationTuple.Item3; var authorizationResult = await webUi.AcquireAuthorizationAsync( authorizationUri, _requestParams.RedirectUri, _requestParams.RequestContext, cancellationToken).ConfigureAwait(false); VerifyAuthorizationResult(authorizationResult, state); return(new Tuple <AuthorizationResult, string>(authorizationResult, codeVerifier)); }
private static void AssertInvalidRedirectUri(IWebUI webUI, string uri) { var ex = AssertException.Throws <MsalClientException>(() => webUI.ValidateRedirectUri(new Uri(uri))); Assert.AreEqual(MsalError.LoopbackRedirectUri, ex.ErrorCode); }
public RecorderWebUI(PromptBehavior promptBehavior, object ownerWindow) { this.internalWebUI = (new WebUIFactory()).Create(promptBehavior, ownerWindow); }
private async Task <AuthenticationResult> AcquireTokenWithClaimsCommonAsync(string resource, ClientKey clientKey, Uri redirectUri, IPlatformParameters parameters, UserIdentifier userId, string extraQueryParameters, IWebUI webUI, string claims) { RequestData requestData = new RequestData { Authenticator = this.Authenticator, TokenCache = this.TokenCache, Resource = resource, ClientKey = clientKey, ExtendedLifeTimeEnabled = this.ExtendedLifeTimeEnabled }; var handler = new AcquireTokenInteractiveHandler(requestData, redirectUri, parameters, userId, extraQueryParameters, webUI, claims); return(await handler.RunAsync().ConfigureAwait(false)); }
public InteractiveRequest(AuthenticationRequestParameters authenticationRequestParameters, string[] additionalScope, Uri redirectUri, IPlatformParameters parameters, User user, UiOptions uiOptions, string extraQueryParameters, IWebUI webUI) : this(authenticationRequestParameters, additionalScope, redirectUri, parameters, user?.DisplayableId, uiOptions, extraQueryParameters, webUI) { this.User = user; }
public RecorderWebUI(IPlatformParameters parameters) { this.internalWebUI = (new WebUIFactory()).CreateAuthenticationDialog(parameters); }
public void NoCacheLookup() { Authenticator authenticator = new Authenticator(TestConstants.DefaultAuthorityHomeTenant, false, Guid.NewGuid()); TokenCache cache = new TokenCache(); TokenCacheKey key = new TokenCacheKey(TestConstants.DefaultAuthorityHomeTenant, TestConstants.DefaultScope, TestConstants.DefaultClientId, TestConstants.DefaultUniqueId, TestConstants.DefaultDisplayableId, TestConstants.DefaultHomeObjectId, TestConstants.DefaultPolicy); AuthenticationResultEx ex = new AuthenticationResultEx(); ex.Result = new AuthenticationResult("Bearer", key.ToString(), new DateTimeOffset(DateTime.UtcNow + TimeSpan.FromSeconds(3599))); ex.Result.User = new User { DisplayableId = TestConstants.DefaultDisplayableId, UniqueId = TestConstants.DefaultUniqueId, HomeObjectId = TestConstants.DefaultHomeObjectId }; ex.Result.FamilyId = "1"; ex.RefreshToken = "someRT"; cache.tokenCacheDictionary[key] = ex; IWebUI ui = Substitute.For <IWebUI>(); AuthorizationResult ar = new AuthorizationResult(AuthorizationStatus.Success, TestConstants.DefaultAuthorityHomeTenant + "?code=some-code"); ui.AcquireAuthorizationAsync(Arg.Any <Uri>(), Arg.Any <Uri>(), Arg.Any <IDictionary <string, string> >(), Arg.Any <CallState>()) .Returns(ar); MockHttpMessageHandler mockHandler = new MockHttpMessageHandler(); mockHandler.Method = HttpMethod.Post; mockHandler.QueryParams = new Dictionary <string, string>() { { "p", "some-policy" } }; mockHandler.ResponseMessage = MockHelpers.CreateSuccessTokenResponseMessage(); HttpMessageHandlerFactory.MockHandler = mockHandler; AuthenticationRequestParameters parameters = new AuthenticationRequestParameters() { Authenticator = authenticator, ClientKey = new ClientKey(TestConstants.DefaultClientId), Policy = "some-policy", RestrictToSingleUser = TestConstants.DefaultRestrictToSingleUser, Scope = TestConstants.DefaultScope.ToArray(), TokenCache = cache }; InteractiveRequest request = new InteractiveRequest(parameters, TestConstants.ScopeForAnotherResource.ToArray(), new Uri("some://uri"), new PlatformParameters(), TestConstants.DefaultDisplayableId, UiOptions.SelectAccount, "extra=qp", ui); Task <AuthenticationResult> task = request.RunAsync(); task.Wait(); AuthenticationResult result = task.Result; Assert.IsNotNull(result); Assert.AreEqual(2, cache.Count); Assert.AreEqual(result.Token, "some-access-token"); //both cache entry authorities are TestConstants.DefaultAuthorityHomeTenant foreach (var item in cache.ReadItems(TestConstants.DefaultClientId)) { Assert.AreEqual(TestConstants.DefaultAuthorityHomeTenant, item.Authority); } }
public InteractiveRequest(AuthenticationRequestParameters authenticationRequestParameters, string[] additionalScope, Uri redirectUri, IPlatformParameters parameters, User user, UiOptions uiOptions, string extraQueryParameters, IWebUI webUI) :this(authenticationRequestParameters, additionalScope, redirectUri, parameters, user?.DisplayableId, uiOptions, extraQueryParameters, webUI) { this.User = user; }
public AcquireTokenInteractiveHandler(HandlerData handlerData, string[] additionalScope, Uri redirectUri, IPlatformParameters parameters, User user, UiOptions uiOptions, string extraQueryParameters, IWebUI webUI) : this(handlerData, additionalScope, redirectUri, parameters, user?.DisplayableId, uiOptions, extraQueryParameters, webUI) { this.User = user; }
public InteractiveRequest(AuthenticationRequestParameters authenticationRequestParameters, IEnumerable <string> extraScopesToConsent, UIBehavior UIBehavior, IWebUI webUI) : this( authenticationRequestParameters, extraScopesToConsent, authenticationRequestParameters.User?.DisplayableId, UIBehavior, webUI) { }
public AcquireTokenInteractiveHandler(RequestData requestData, Uri redirectUri, IPlatformParameters parameters, UserIdentifier userId, string extraQueryParameters, IWebUI webUI, string claims) : base(requestData) { this.redirectUri = platformInformation.ValidateRedirectUri(redirectUri, this.CallState); if (!string.IsNullOrWhiteSpace(this.redirectUri.Fragment)) { throw new ArgumentException(AdalErrorMessage.RedirectUriContainsFragment, "redirectUri"); } this.authorizationParameters = parameters; this.redirectUriRequestParameter = platformInformation.GetRedirectUriAsString(this.redirectUri, this.CallState); if (userId == null) { throw new ArgumentNullException("userId", AdalErrorMessage.SpecifyAnyUser); } this.userId = userId; if (!string.IsNullOrEmpty(extraQueryParameters) && extraQueryParameters[0] == '&') { extraQueryParameters = extraQueryParameters.Substring(1); } this.extraQueryParameters = extraQueryParameters; this.webUi = webUI; this.UniqueId = userId.UniqueId; this.DisplayableId = userId.DisplayableId; this.UserIdentifierType = userId.Type; this.SupportADFS = true; if (!String.IsNullOrEmpty(claims)) { this.LoadFromCache = false; CallState.Logger.Verbose(CallState, "Claims present. Skip cache lookup."); this.claims = claims; } else { this.LoadFromCache = (requestData.TokenCache != null && parameters != null && platformInformation.GetCacheLoadPolicy(parameters)); } this.brokerParameters["force"] = "NO"; if (userId != UserIdentifier.AnyUser) { this.brokerParameters["username"] = userId.Id; } else { this.brokerParameters["username"] = string.Empty; } this.brokerParameters["username_type"] = userId.Type.ToString(); this.brokerParameters["redirect_uri"] = this.redirectUri.AbsoluteUri; this.brokerParameters["extra_qp"] = extraQueryParameters; this.brokerParameters["claims"] = claims; brokerHelper.PlatformParameters = authorizationParameters; }