private static void SanetizeCallbackPath(ExternalProvider entity, AuthenticationSchemeOptions options)
 {
     if (options is RemoteAuthenticationOptions remoteAuthenticationOptions)
     {
         remoteAuthenticationOptions.CallbackPath = $"/signin-{entity.Id}";
     }
 }
Exemple #2
0
 public void ConfigureAuthorization(AuthenticationSchemeOptions options, IConfiguration configuration, ILogger logger)
 {
     options.Events = new OpenIdConnectEvents
     {
         OnRedirectToIdentityProvider = (ctx) => Redirect(configuration, ctx),
         OnTokenValidated             = (ctx) => AfterTokenValidated(configuration, ctx),
         OnAuthenticationFailed       = (ctx) => LogAuthenticationFailed(logger, ctx),
     };
 }
Exemple #3
0
        /// <summary>
        /// Tries to adds a new option to the cache, will return false if the name already exists.
        /// </summary>
        /// <param name="name">The name of the options instance.</param>
        /// <param name="options">The options instance.</param>
        /// <returns>Whether anything was added.</returns>
        public bool TryAdd(string name, AuthenticationSchemeOptions options)
        {
            var result = _parent.TryAdd(name, (TOptions)options);

            _onAdded.Invoke(name, options as TOptions);
            foreach (var postConfigure in _postConfigures)
            {
                postConfigure.PostConfigure(name, options as TOptions);
            }
            return(result);
        }
Exemple #4
0
        public async Task Setup()
        {
            var logger        = new Mock <ILogger <AuthenticationHandler> >();
            var loggerFactory = new Mock <ILoggerFactory>(MockBehavior.Strict);

            loggerFactory.Setup(x => x.CreateLogger(typeof(AuthenticationHandler).FullName)).Returns(logger.Object);


            var options = new AuthenticationSchemeOptions();
            var om      = new Mock <IOptionsMonitor <AuthenticationSchemeOptions> >(MockBehavior.Strict);

            om.Setup(x => x.Get(It.IsAny <string>())).Returns(options);

            _systemClockMock           = new Mock <ISystemClock>();
            _urlEncoderMock            = new Mock <UrlEncoder>();
            _authenticationServiceMock = new Mock <IAuthenticationService>();
            _tokenRepositoryMock       = new Mock <ITokenRepository>();
            _authenticationHandler     = new AuthenticationHandler(om.Object, loggerFactory.Object, _urlEncoderMock.Object, _systemClockMock.Object, _authenticationServiceMock.Object, _tokenRepositoryMock.Object);

            _context = new DefaultHttpContext();

            await _authenticationHandler.InitializeAsync(new AuthenticationScheme("", "", typeof(AuthenticationHandler)), _context);
        }
 /// <summary>
 /// Serializes the specified options.
 /// </summary>
 /// <param name="options">The options.</param>
 /// <param name="optionsType">Type of the options.</param>
 /// <returns>The serialized result.</returns>
 public virtual string SerializeOptions(AuthenticationSchemeOptions options, Type optionsType)
 {
     return(Serialize(options, optionsType));
 }
Exemple #6
0
 public DynamicAuthenticationScheme(string name, string displayName, Type handlerType,
                                    AuthenticationSchemeOptions options, SsoType ssoType)
     : this(name, displayName, handlerType, options)
 {
     SsoType = ssoType;
 }
Exemple #7
0
 public DynamicAuthenticationScheme(string name, string displayName, Type handlerType,
                                    AuthenticationSchemeOptions options)
     : base(name, displayName, handlerType)
 {
     Options = options;
 }