Example #1
0
 public AuthController(IAuthService authService, IOptions <FacebookAuthSettings> fbAuthSettingsAccessor, IJwtFactory jwtFactory, IOptions <JwtIssuerOptions> jwtOptions)
 {
     _authService    = authService;
     _fbAuthSettings = fbAuthSettingsAccessor.Value;
     _jwtFactory     = jwtFactory;
     _jwtOptions     = jwtOptions.Value;
 }
Example #2
0
        public AccountController(
            UserManager <ApplicationUser> userManager,
            IJwtService jwtService,
            SignInManager <ApplicationUser> signInManager,
            IUserService userService,
            ISmtpService smtpService,
            IEmailSenderService emailService,
            RoleManager <ApplicationRole> roleManager,
            IIdentityService identityService,
            IOptions <FacebookAuthSettings> fbAuthSettingsAccessor
            )
        {
            _serializerSettings = new JsonSerializerSettings
            {
                Formatting = Formatting.Indented
            };

            this._userManager     = userManager;
            this._jwtService      = jwtService;
            this._userService     = userService;
            this._signInManager   = signInManager;
            this._smtpService     = smtpService;
            this._emailService    = emailService;
            this._identityService = identityService;
            this._fbAuthSettings  = fbAuthSettingsAccessor.Value;
            _roleManager          = roleManager;
        }
Example #3
0
 public FacebookIdentity(IOptions <FacebookAuthSettings> fbAuthSettings, UserManager <User> userManager, IJwtFactory jwtFactory, IUserRepository userRepository)
 {
     _fbAuthSettings = fbAuthSettings.Value;
     _userManager    = userManager;
     _jwtFactory     = jwtFactory;
     _userRepository = userRepository;
 }
 public FacebookAuthService(FacebookAuthSettings facebookAuthSettings, IHttpClientFactory httpClientFactory)
 {
     _facebookAuthSettings  = facebookAuthSettings;
     _httpClientFactory     = httpClientFactory;
     UserInfoUrl            = _facebookAuthSettings.UserInfoUrl;
     ValidateAccessTokenUrl = _facebookAuthSettings.ValidateAccessTokenUrl;
 }
Example #5
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            IdentityModelEventSource.ShowPII = true; // show error details
            var facebookAuthSettings = new FacebookAuthSettings();

            services.Configure <FormOptions>(options =>
            {
                options.MemoryBufferThreshold = Int32.MaxValue;
            });

            // requires using Microsoft.Extensions.Options
            services.Configure <UserDatabaseSettings>(Configuration.GetSection(nameof(UserDatabaseSettings)));
            services.AddSingleton <IUserDatabaseSettings>(sp => sp.GetRequiredService <IOptions <UserDatabaseSettings> >().Value);
            services.AddSingleton <UserService>();

            services.Configure <EventDatabaseSettings>(Configuration.GetSection(nameof(EventDatabaseSettings)));
            services.AddSingleton <IEventDatabaseSettings>(sp => sp.GetRequiredService <IOptions <EventDatabaseSettings> >().Value);
            services.AddSingleton <EventService>();

            services.Configure <ItemDatabaseSettings>(Configuration.GetSection(nameof(ItemDatabaseSettings)));
            services.AddSingleton <IItemDatabaseSettings>(sp => sp.GetRequiredService <IOptions <ItemDatabaseSettings> >().Value);
            services.AddSingleton <ItemService>();

            services.Configure <NotificationDatabaseSettings>(Configuration.GetSection(nameof(NotificationDatabaseSettings)));
            services.AddSingleton <INotificationDatabaseSettings>(sp => sp.GetRequiredService <IOptions <NotificationDatabaseSettings> >().Value);
            services.AddSingleton <NotificationService>();

            services.Configure <InvitationDatabaseSettings>(Configuration.GetSection(nameof(InvitationDatabaseSettings)));
            services.AddSingleton <IInvitationDatabaseSettings>(sp => sp.GetRequiredService <IOptions <InvitationDatabaseSettings> >().Value);
            services.AddSingleton <InvitationService>();

            services.Configure <ProfilePictureDatabaseSettings>(Configuration.GetSection(nameof(ProfilePictureDatabaseSettings)));
            services.AddSingleton <IProfilePictureDatabaseSettings>(sp => sp.GetRequiredService <IOptions <ProfilePictureDatabaseSettings> >().Value);
            services.AddSingleton <ProfilePictureService>();

            Configuration.Bind(nameof(FacebookAuthSettings), facebookAuthSettings);
            services.AddSingleton(facebookAuthSettings);

            services.AddHttpClient();
            services.AddSingleton <FacebookAuthService>();
            services.AddSingleton <GoogleAuthService>();
            // services.AddSingleton<EmailService>();

            services.AddControllers().AddNewtonsoftJson(options => options.UseMemberCasing());
            services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme).AddJwtBearer(options =>
            {
                options.SaveToken = true;
                options.TokenValidationParameters = new TokenValidationParameters()
                {
                    ValidateIssuer           = true,
                    ValidateAudience         = true,
                    ValidateLifetime         = true,
                    ValidateIssuerSigningKey = true,
                    ValidIssuer      = Configuration["jwt:issuer"],
                    ValidAudience    = Configuration["jwt:issuer"],
                    IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(this.Configuration["jwt:key"]))
                };
            });
        }
Example #6
0
 public ExternalAuthController(IOptions <FacebookAuthSettings> fbAuthSettingsAccessor, IUserService userService, ICommandBus commadBus, IJwtFactory jwtFactory, IOptions <JwtIssuerOptions> jwtOptions)
 {
     _fbAuthSettings = fbAuthSettingsAccessor.Value;
     _userService    = userService ?? throw new ArgumentNullException(nameof(userService));
     _commadBus      = commadBus ?? throw new ArgumentNullException(nameof(commadBus));
     _jwtFactory     = jwtFactory;
     _jwtOptions     = jwtOptions.Value;
 }
 public AccountController(UserManager <User> userManager,
                          IOptions <JwtOptions> jwtOptions,
                          IOptions <FacebookAuthSettings> fbOpts)
 {
     _userManager          = userManager;
     _jwtoptions           = jwtOptions.Value;
     _facebookAuthSettings = fbOpts.Value;
 }
 public FacebookController(IOptions <FacebookAuthSettings> fbAuthSettingsAccessor, UserManager <AppUser> userManager, NetCore21AuthDbContext appDbContext, IJwtFactory jwtFactory, IOptions <JwtOptions> jwtOptions)
 {
     _fbAuthSettings = fbAuthSettingsAccessor.Value;
     _userManager    = userManager;
     _appDbContext   = appDbContext;
     _jwtFactory     = jwtFactory;
     _jwtOptions     = jwtOptions.Value;
 }
 public ExternalAuthController(IOptions <FacebookAuthSettings> fbAuthSettingsAccessor, UserManager <AppUser> userManager, IUnitOfWork unitOfWork, IJwtFactory jwtFactory, IOptions <JwtIssuerOptions> jwtOptions)
 {
     fbAuthSettings   = fbAuthSettingsAccessor.Value;
     this.userManager = userManager;
     this.unitOfWork  = unitOfWork;
     this.jwtFactory  = jwtFactory;
     this.jwtOptions  = jwtOptions.Value;
 }
Example #10
0
 /// <summary>
 /// ctor
 /// </summary>
 public ExternalAuthController(IOptions <FacebookAuthSettings> fbAuthSetting, UserManager <AppUser> userManager, UserContext userContext, ITokenUtility tokenUtility, IOptions <JwtSettingOptions> jwtOptions)
 {
     _fbAuthSettings = fbAuthSetting.Value;
     _userManager    = userManager;
     _userContext    = userContext;
     _tokenUtility   = tokenUtility;
     _jwtOptions     = jwtOptions.Value;
 }
Example #11
0
 public ExternalAuthController(IOptions <FacebookAuthSettings> fbAuthSettingsAccessor, UserManager <AppUser> userManager, MariaDbContext appDbContext, IJwtFactory jwtFactory, IOptions <JwtIssuerOptions> jwtOptions)
 {
     _fbAuthSettings = fbAuthSettingsAccessor.Value;
     _userManager    = userManager;
     _appDbContext   = appDbContext;
     _jwtFactory     = jwtFactory;
     _jwtOptions     = jwtOptions.Value;
 }
Example #12
0
 public LoginService(IConfiguration configuration, ITokenService tokenService, IEmailService emailService, IUnitOfWork unitOfWork, IMapper mapper, IOptions <FacebookAuthSettings> fbAuthSettingsAccessor)
 {
     _configuration  = configuration;
     _tokenService   = tokenService;
     _emailService   = emailService;
     _unitOfWork     = unitOfWork;
     _mapper         = mapper;
     _fbAuthSettings = fbAuthSettingsAccessor.Value;
 }
Example #13
0
 public ExternalAuthController(IOptions <FacebookAuthSettings> fbAuthSettingsAccessor, UserManager <User> userManager,
                               CrowdfundingSystemContext context, IJwtFactory jwtFactory, IOptions <JwtIssuerOptions> jwtOptions)
 {
     fbAuthSettings   = fbAuthSettingsAccessor.Value;
     this.userManager = userManager;
     this.context     = context;
     this.jwtFactory  = jwtFactory;
     this.jwtOptions  = jwtOptions.Value;
 }
 public ExternalLoginController(IOptions <GoogleAuthSettings> ggAuthSettings, IOptions <FacebookAuthSettings> fbAuthSettingsAccessor
                                , UserManager <User> userManager, SaleDBContext appDbContext, IOptions <JwtIssuerOptions> jwtOptions)
 {
     _userManager    = userManager;
     _appDbContext   = appDbContext;
     _jwtOptions     = jwtOptions.Value;
     _ggAuthSettings = ggAuthSettings.Value;
     _fbAuthSettings = fbAuthSettingsAccessor.Value;
 }
Example #15
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddCors();
            var jwtSettings           = new JWTSettings();
            var identityUrl           = Configuration.GetValue <string>("IdentityUrl");
            var callbackUrl           = Configuration.GetValue <string>("CallBackUrl");
            var sessionCookieLifetime = Configuration.GetValue("SessionCookieLifetime", 60);

            services.Configure <FacebookAuthSettings>(Configuration.GetSection("JWTSettings"));

            Configuration.GetSection("JWTSettings").Bind(jwtSettings);
            var facebookAuthSettings = new FacebookAuthSettings();

            services.Configure <FacebookAuthSettings>(Configuration.GetSection("FacebookAuthSettings"));
            Configuration.GetSection("FacebookAuthSettings").Bind(facebookAuthSettings);
            services.AddSingleton(facebookAuthSettings);
            services.AddSingleton(jwtSettings);
            services.AddSingleton <IFacebookInterface, FacebookRepo>();
            services.AddSingleton <IHttpContextAccessor, HttpContextAccessor>();
            services.AddScoped <IToken, TokenRepo>();
            services.AddScoped <IUserInterfaces, UserService>();

            services.AddScoped <IIdentityService, IdentityService>();
            services.AddRouting();
            services.AddControllers();
            services.AddRazorPages();
            services.AddControllersWithViews(options => options.InputFormatters.Insert(0, new RawJsonBodyInputFormatter())).AddNewtonsoftJson(options =>
                                                                                                                                              options.SerializerSettings.ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore);
            services.AddSession(option => option.IdleTimeout = TimeSpan.FromSeconds(60 * 90));
            services.AddAuthentication(option =>
            {
                option.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme;
                option.DefaultScheme             = JwtBearerDefaults.AuthenticationScheme;
                option.DefaultChallengeScheme    = JwtBearerDefaults.AuthenticationScheme;
            }
                                       ).AddJwtBearer(x =>
            {
                x.SaveToken = true;
                x.TokenValidationParameters = new Microsoft.IdentityModel.Tokens.TokenValidationParameters
                {
                    ValidateIssuerSigningKey = true,
                    IssuerSigningKey         = new SymmetricSecurityKey(Encoding.ASCII.GetBytes(jwtSettings.Secret)),
                    ValidateIssuer           = false,
                    ValidateAudience         = false,
                    RequireExpirationTime    = false,
                    ValidateLifetime         = false,
                };
            }
                                                      ).AddCookie(setup => setup.ExpireTimeSpan = TimeSpan.FromMinutes(sessionCookieLifetime));


            services.AddDefaultIdentity <IdentityUser>(options => options.SignIn.RequireConfirmedAccount = true)
            .AddEntityFrameworkStores <ApplicationDbContext>();

            services.AddHttpClient();
        }
        public ExternalAuthController(IOptions <FacebookAuthSettings> fbAuthSettingsAccessor, UserManager <User> userManager)
        {
            facebookAuthSettings = fbAuthSettingsAccessor.Value;
            this.config          = config;
            this.userManager     = userManager;
            this.signInManager   = signInManager;
            this.mapper          = mapper;

            externalAuthService = new ExternalAuthService <AppContext>(config, userManager, mapper);
        }
Example #17
0
 public AuthenticationService(UserManager <User> userManager, SignInManager <User> signInManager, IJwtUser user, IOptions <JwtSettings> jwtSettings, IOptions <FacebookAuthSettings> facebookAuthSettings, IOptions <RefreshTokenSettings> refreshTokenSettings, IdentityDbContext context, IMapper mapper)
 {
     this.UserManager          = userManager;
     this.SignInManager        = signInManager;
     this.JwtSettings          = jwtSettings.Value;
     this.FacebookAuthSettings = facebookAuthSettings.Value;
     this.RefreshTokenSettings = refreshTokenSettings.Value;
     this.Context = context;
     this.Mapper  = mapper;
 }
Example #18
0
        public void InstallServices(IConfiguration configuration, IServiceCollection services)
        {
            var faceAuthSettings = new FacebookAuthSettings();

            configuration.Bind(nameof(FacebookAuthSettings), faceAuthSettings);
            services.AddSingleton(faceAuthSettings);

            services.AddHttpClient();
            services.AddSingleton <IFacebookAuthService, FacebookAuthService>();
        }
Example #19
0
 /// <inheritdoc />
 public AccountController(IAuthentication auth, IOptions <FacebookAuthSettings> fbAuthSettingsAccessor,
                          IHttpContextAccessor httpContextAccessor, IAuthorization authorize, IAuthenticationService authService, ILogger <AccountController> logger)
 {
     _fbAuthSettings      = fbAuthSettingsAccessor.Value;
     _auth                = auth;
     _authorize           = authorize;
     _httpContextAccessor = httpContextAccessor;
     _authService         = authService;
     _logger              = logger;
 }
Example #20
0
        public UsersController(IConfiguration configuration, IUserRepository userRepository, IMapper mapper, ILogger <UsersController> logger) : base(logger, userRepository)
        {
            _fbAuthSettings = new FacebookAuthSettings
            {
                AppId     = configuration["Authentication:Facebook:AppId"],
                AppSecret = configuration["Authentication:Facebook:AppSecret"]
            };

            UserRepository = userRepository;
            Mapper         = mapper;
        }
Example #21
0
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddApplication <blogWebModule>();
            //services.AddIdentity<AppUser, IdentityRole>();

            services.AddAuthentication()
            .AddFacebook(facebook =>
            {
                facebook.AppId     = Configuration["FacebookAuth:AppID"];
                facebook.AppSecret = Configuration["FacebookAuth:AppSecret"];
            })
            .AddGoogle(ggOptions =>
            {
                ggOptions.ClientId     = Configuration["GoogleAuth:ClientId"];
                ggOptions.ClientSecret = Configuration["GoogleAuth:ClientSecret"];
            });

            services.AddScoped <ICateAppService, CategoryService>();
            services.AddScoped <IPostAppService, PostService>();
            services.AddScoped <IAccountAppService, AccountAppService>();
            services.AddScoped <IPermissionAppService, PermissionAppService>();
            services.AddScoped <IIdentityRoleAppService, IdentityRoleAppSerivce>();
            services.AddScoped <IIdentityAppService, IdentityAppService>();
            services.AddScoped <IDocumentAppService, DocumentAppService>();

            var jwtSettings = new JwtSetting();

            Configuration.Bind(nameof(jwtSettings), jwtSettings);
            services.AddSingleton(jwtSettings);

            //Facebook Auth
            var facebookAuthSettings = new FacebookAuthSettings();

            Configuration.Bind(nameof(FacebookAuthSettings), facebookAuthSettings);
            services.AddSingleton(facebookAuthSettings);
            services.AddHttpClient();
            services.AddSingleton <IFacebookAuthService, FacebookAuthService>();

            //Config uri service
            services.AddScoped <IUriService, UriService>();
            services.AddSingleton <IUriService>(provider =>
            {
                //add DI IUriService-UriService, lấy baseUri để đưa cho hàm tạo của UriService
                //Khi ta gửi request đến server, request đó sẽ chứa các thuộc tính như: path/scheme/..
                //Ví dụ gửi request xem tất cả các post
                //scheme: https
                //path: api/v1/posts
                var accessor    = provider.GetRequiredService <IHttpContextAccessor>();
                var request     = accessor.HttpContext.Request;
                var absoluteUri = string.Concat(request.Scheme, "://", request.Host.ToUriComponent(), "/");
                return(new UriService(absoluteUri));
            });
        }
 public ExternalAuthController(IOptions <FacebookAuthSettings> fbAuthSettingsAccessor, UserManager <ApplicationUser> userManager,
                               IJwtFactory jwtFactory, IOptions <JwtIssuerOptions> jwtOptions,
                               IHttpContextAccessor contextAccessor,
                               IUnitOfWork unitOfWork,
                               ILogger <ExternalAuthController> logger) : base(logger)
 {
     _fbAuthSettings  = fbAuthSettingsAccessor.Value;
     _userManager     = userManager;
     _jwtFactory      = jwtFactory;
     _contextAccessor = contextAccessor;
     _unitOfWork      = unitOfWork;
     _jwtOptions      = jwtOptions.Value;
 }
 public FacebookAuthController(
     IConfiguration config,
     IMapper mapper,
     IOptions <FacebookAuthSettings> fbAuthSettingsAccessor,
     UserManager <User> userManager,
     SignInManager <User> signInManager)
 {
     _mapper         = mapper;
     _config         = config;
     _fbAuthSettings = fbAuthSettingsAccessor.Value;
     _userManager    = userManager;
     _signInManager  = signInManager;
 }
 public ExternalAuthService(
     IJwtFactory jwtFactory,
     IOptions <JwtIssuerOptions> jwtOptions,
     IOptions <FacebookAuthSettings> fbAuthSettingsAccessor,
     UserManager <UserEntity> userManager,
     ApplicationDbContext appDbContext)
 {
     this.jwtFactory     = jwtFactory;
     this.jwtOptions     = jwtOptions.Value;
     this.fbAuthSettings = fbAuthSettingsAccessor.Value;
     this.userManager    = userManager;
     this.appDbContext   = appDbContext;
 }
 public ExternalAuthController(IOptions <FacebookAuthSettings> fbAuthSettingsAccessor,
                               KullaniciYonetici userManager,
                               SignInManager <Kullanici> signInManager,
                               MTIdentityDbContext appDbContext,
                               IJwtFactory jwtFactory,
                               IOptions <JwtIssuerOptions> jwtOptions)
 {
     _fbAuthSettings    = fbAuthSettingsAccessor.Value;
     _userManager       = userManager;
     this.signInManager = signInManager;
     _appDbContext      = appDbContext;
     _jwtFactory        = jwtFactory;
     _jwtOptions        = jwtOptions.Value;
 }
 public ExternalLoginController(IOptions <FacebookAuthSettings> fbAuthSettingsAccessor,
                                UserManager <AppUser> userManager,
                                ApplicationDbContext appDbContext,
                                IJwtFactory jwtFactory,
                                IOptions <JwtIssuerOptions> jwtOptions,
                                IRefreshTokenRepository refreshTokenRepository)
 {
     _fbAuthSettings         = fbAuthSettingsAccessor.Value;
     _userManager            = userManager;
     _appDbContext           = appDbContext;
     _jwtFactory             = jwtFactory;
     _jwtOptions             = jwtOptions.Value;
     _refreshTokenRepository = refreshTokenRepository;
 }
        public FacebookAuthController(UserManager <DbUser> userManager,
                                      RoleManager <DbRole> roleManager,
                                      SignInManager <DbUser> signInManager,
                                      IFileService fileService,
                                      IJWTTokenService jWTTokenService,
                                      IOptions <FacebookAuthSettings> fbAuthSettingsAccessor)

        {
            _userManager     = userManager;
            _signInManager   = signInManager;
            _fileService     = fileService;
            _roleManager     = roleManager;
            _fbAuthSettings  = fbAuthSettingsAccessor.Value;
            _jWTTokenService = jWTTokenService;
        }
 public AccountController(UserManager <AppUser> userManager, ITokenLogService tokenLogService, ICompanyService companyService, IJwtFactory jwtFactory, SignInManager <AppUser> signInManager, IEmailSender emailSender, IConfiguration configuration, RoleManager <IdentityRole> roleManager, IOptions <JwtIssuerOptions> jwtOptions, IOptions <FacebookAuthSettings> fbAuthSettingsAccessor, IHostingEnvironment environment, ImpressoDbContext appDbContext)
 {
     _userManager        = userManager;
     _jwtFactory         = jwtFactory;
     _signInManager      = signInManager;
     _emailSender        = emailSender;
     _configuration      = configuration;
     _roleManager        = roleManager;
     _fbAuthSettings     = fbAuthSettingsAccessor.Value;
     _jwtOptions         = jwtOptions.Value;
     _hostingEnvironment = environment;
     _appDbContext       = appDbContext;
     _companyService     = companyService;
     _tokenLogService    = tokenLogService;
 }
Example #29
0
 public FacebookExternalLoginHandler(
     ILogger <GetUserProvidersHandler> logger,
     UserManager <Models.AppUser> userManager,
     IOptions <FacebookAuthSettings> fbAuthSettingsAccessor,
     HttpClient httpClient,
     IJwtFactory jwtFactory,
     IMapper mapper
     )
 {
     _logger         = logger;
     _userManager    = userManager;
     _httpClient     = httpClient;
     _fbAuthSettings = fbAuthSettingsAccessor.Value;
     _jwtFactory     = jwtFactory;
     _mapper         = mapper;
 }
Example #30
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            var facebookAuthSettings = new FacebookAuthSettings();

            Configuration.Bind(nameof(FacebookAuthSettings), facebookAuthSettings);
            services.AddSingleton(facebookAuthSettings);
            services.AddHttpClient();
            services.AddTransient <IFacebookAuthService, FacebookAuthService>();
            services.AddControllers();
            services.AddSwaggerGen(c =>
            {
                c.SwaggerDoc("v1", new OpenApiInfo {
                    Title = "TestFaceBook", Version = "v1"
                });
            });
        }