Beispiel #1
0
 private static void RegisterCoreServices(this TrustedDeviceAuthorizationOptions options)
 {
     options.Services.AddTransient <BearerTokenUsageValidator>();
     options.Services.AddTransient <CompleteRegistrationRequestValidator>();
     options.Services.AddTransient <CompleteRegistrationResponseGenerator>();
     options.Services.AddTransient <DeviceAuthorizationRequestValidator>();
     options.Services.AddTransient <DeviceAuthorizationResponseGenerator>();
     options.Services.AddTransient <InitRegistrationRequestValidator>();
     options.Services.AddTransient <InitRegistrationResponseGenerator>();
 }
Beispiel #2
0
        /// <summary>
        /// Register the endpoints and required services for trusted device authorization.
        /// </summary>
        /// <param name="builder">IdentityServer builder interface.</param>
        /// <param name="configureAction"></param>
        public static IIdentityServerBuilder AddTrustedDeviceAuthorization(this IIdentityServerBuilder builder, Action <TrustedDeviceAuthorizationOptions> configureAction = null)
        {
            var options = new TrustedDeviceAuthorizationOptions {
                Services = builder.Services
            };

            configureAction?.Invoke(options);
            // Register endpoints.
            builder.RegisterEndpoints();
            // Register stores and services.
            builder.Services.AddTransient <IAuthorizationCodeChallengeStore, DefaultAuthorizationCodeChallengeStore>();
            builder.Services.TryAddTransient <IPlatformEventService, PlatformEventService>();
            builder.Services.TryAddScoped <IdentityMessageDescriber>();
            options.AddUserDeviceStoreInMemory();
            // Register custom grant validator.
            builder.AddExtensionGrantValidator <TrustedDeviceExtensionGrantValidator>();
            // Register core services.
            options.AddDefaultPasswordHasher();
            options.RegisterCoreServices();
            return(builder);
        }
Beispiel #3
0
 /// <summary>
 /// Registers an implementation of the mechanism that performs password hashing and validation for devices.
 /// </summary>
 /// <typeparam name="TDevicePasswordHasher">The type of <see cref="IDevicePasswordHasher"/> implementation to register.</typeparam>
 /// <param name="options">Options for configuring 'Trusted Device Authorization' feature.</param>
 public static void AddDevicePasswordHasher <TDevicePasswordHasher>(this TrustedDeviceAuthorizationOptions options) where TDevicePasswordHasher : IDevicePasswordHasher =>
 options.Services.AddTransient(typeof(IDevicePasswordHasher), typeof(TDevicePasswordHasher));
Beispiel #4
0
 /// <summary>
 /// Adds the default hashing mechanism for devices.
 /// </summary>
 /// <param name="options">Options for configuring 'Trusted Device Authorization' feature.</param>
 public static void AddDefaultPasswordHasher(this TrustedDeviceAuthorizationOptions options)
 {
     options.Services.TryAddTransient <IDevicePasswordHasher, DefaultDevicePasswordHasher>();
     options.Services.TryAddScoped <PasswordHasher <User> >();
 }
Beispiel #5
0
 /// <summary>
 /// Adds a custom implementation for <see cref="IUserDeviceStore"/> store.
 /// </summary>
 /// <typeparam name="TUserDeviceStore">The type of <see cref="UserDevice"/> store.</typeparam>
 /// <param name="options">Options for configuring 'Trusted Device Authorization' feature.</param>
 public static void AddUserDeviceStore <TUserDeviceStore>(this TrustedDeviceAuthorizationOptions options) where TUserDeviceStore : class, IUserDeviceStore =>
 options.Services.AddTransient <IUserDeviceStore, TUserDeviceStore>();
Beispiel #6
0
 /// <summary>
 /// Add an implementation of <see cref="IUserDeviceStore"/> for persisting user devices in a relational database using Entity Framework Core.
 /// </summary>
 /// <param name="options">Options for configuring 'Trusted Device Authorization' feature.</param>
 public static void AddUserDeviceStoreEntityFrameworkCore(this TrustedDeviceAuthorizationOptions options) =>
 options.AddUserDeviceStore <UserDeviceStoreEntityFrameworkCore>();
Beispiel #7
0
 /// <summary>
 /// Adds an in-memory implementation for the <see cref="IUserDeviceStore"/> store.
 /// </summary>
 /// <param name="options">Options for configuring 'Trusted Device Authorization' feature.</param>
 public static void AddUserDeviceStoreInMemory(this TrustedDeviceAuthorizationOptions options) =>
 options.Services.TryAddSingleton <IUserDeviceStore, UserDeviceStoreInMemory>();