Exemple #1
0
 public LoginEndpoint(IAMOptions options, IOptions <MvcNewtonsoftJsonOptions> mvcNewtonsoftJsonOptions,
                      IUserService userService, IStringLocalizer <Request> requestLocalizer)
     : base(options, mvcNewtonsoftJsonOptions)
 {
     _userService      = userService;
     _requestLocalizer = requestLocalizer;
 }
Exemple #2
0
        public async Task InvokeAsync(HttpContext context, IAMOptions options)
        {
            if (options.UseIAM)
            {
                XTrace.WriteLine("UseIAM");
                var endpoint = context.GetIAMEndpoint();
                if (endpoint != null)
                {
                    XTrace.WriteLine($"GetIAMEndpoint: {endpoint.Path}");

                    await endpoint.ProcessAsync(context);

                    return;
                }

                XTrace.WriteLine($"向授权中心认证:{context.Request.Path}");

                // 请求不是注册登录相关的,在这里向授权中心认证token
                var authenticateResult = await context.AuthenticateAsync(IAMAuthenticationDefaults.AuthenticationScheme);

                if (authenticateResult?.Principal != null)
                {
                    context.User = authenticateResult.Principal;
                }
            }

            await _next(context);
        }
Exemple #3
0
        public EndpointBase(IAMOptions options, IOptions <MvcNewtonsoftJsonOptions> mvcNewtonsoftJsonOptions)
        {
            if (options == null)
            {
                throw new ArgumentNullException(nameof(options));
            }
            if (mvcNewtonsoftJsonOptions == null)
            {
                throw new ArgumentNullException(nameof(mvcNewtonsoftJsonOptions));
            }

            _restClient = new RestClient(options.Url);
            _restClient.UseNewtonsoftJson(mvcNewtonsoftJsonOptions.Value.SerializerSettings);
        }
Exemple #4
0
        public IAMProvider(IHttpContextAccessor httpContextAccessor, IAMOptions options, IOptions <MvcNewtonsoftJsonOptions> mvcNewtonsoftJsonOptions)
        {
            //_httpContextAccessor = httpContextAccessor;
            var options2 = mvcNewtonsoftJsonOptions?.Value ?? throw new ArgumentNullException(nameof(mvcNewtonsoftJsonOptions));

            _jsonSerializerSettings = options2.SerializerSettings;
            _options    = options;
            _restClient = new RestClient(_options.Url);
            _restClient.UseNewtonsoftJson(_jsonSerializerSettings);

            if (httpContextAccessor.HttpContext.Request.Headers.TryGetValue("Authorization", out var token))
            {
                _restClient.AddDefaultHeader("Authorization", token);
            }
        }
Exemple #5
0
        /// <summary>
        /// 添加IAM服务
        /// </summary>
        /// <param name="services"></param>
        public static void AddIAMService(this IServiceCollection services)
        //where TUser : User<TUser>, new()
        {
            var serviceProvider = services.BuildServiceProvider();
            var configuration   = serviceProvider.GetRequiredService <IConfiguration>();
            var options         = new IAMOptions();

            configuration.Bind("IAM", options);
            services.TryAddSingleton(options);

            services.AddScoped <EndpointBase, ChangePasswordEndpoint>();
            // 如果获取本地用户信息,token中的userid在本地不是一一对应,因此可能出现找不到的情况,因此还是采用用户中心信息
            services.AddScoped <EndpointBase, GetUserInfoEndpoint>();
            services.AddScoped <EndpointBase, DeleteAccountEndpoint>();
            services.AddScoped <EndpointBase, LoginEndpoint>();
            services.AddScoped <EndpointBase, RegisterEndpoint>();
            services.AddScoped <EndpointBase, UpdateUserInfoEndpoint>();
            services.AddScoped <EndpointBase, VerCodeEndpoint>();

            //services.TryAddScoped<IAMProvider>();
            //services.TryAddScoped<IUserStore<TUser>, IAMUserStore<TUser>>();
        }
 public DeleteAccountEndpoint(IAMOptions options, IOptions <MvcNewtonsoftJsonOptions> mvcNewtonsoftJsonOptions, IUserService userService) : base(options, mvcNewtonsoftJsonOptions)
 {
     _userService = userService;
 }
Exemple #7
0
 public VerCodeEndpoint(IAMOptions options, IOptions <MvcNewtonsoftJsonOptions> mvcNewtonsoftJsonOptions) : base(options, mvcNewtonsoftJsonOptions)
 {
 }
 public ChangePasswordEndpoint(IAMOptions options, IOptions <MvcNewtonsoftJsonOptions> mvcNewtonsoftJsonOptions) : base(options, mvcNewtonsoftJsonOptions)
 {
 }
Exemple #9
0
 public RegisterEndpoint(IAMOptions options, IOptions <MvcNewtonsoftJsonOptions> mvcNewtonsoftJsonOptions) : base(options, mvcNewtonsoftJsonOptions)
 {
 }
 public UpdateUserInfoEndpoint(IAMOptions options, IOptions <MvcNewtonsoftJsonOptions> mvcNewtonsoftJsonOptions, IUserService userService) : base(options, mvcNewtonsoftJsonOptions)
 {
     _userService = userService;
 }
 public GetUserInfoEndpoint(IAMOptions options, IOptions <MvcNewtonsoftJsonOptions> mvcNewtonsoftJsonOptions) : base(options, mvcNewtonsoftJsonOptions)
 {
 }