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>(); }
/// <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); }
/// <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));
/// <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> >(); }
/// <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>();
/// <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>();
/// <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>();