public async Task <ActionResult <object> > LoginAsync([FromBody] SampekeyUserAccountRequest value) { var data = await account.Login(value); if (data) { return(Ok(new { Token = SampekeyParams.CreateToken(value) })); } else { return(Unauthorized()); } }
public ActionResult <object> GenerateNewToken([FromBody] SampekeyUserAccountRequest value) { return(Ok(new { Token = SampekeyParams.CreateToken(value) })); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2); services.AddOcelot(Configuration); services.AddCors(options => { options.AddPolicy(_crossOrigin, builder => { builder.AllowAnyOrigin() .AllowAnyMethod() .AllowAnyHeader() .AllowCredentials(); }); }); services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme).AddJwtBearer(options => options.TokenValidationParameters = SampekeyParams.GetTokenValidationParameters()); services.AddMvc().AddJsonOptions(ConfigureJson); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.AddControllers(); services.AddDbContext <SampekeyDbContex>(); services.AddIdentity <User, Role>() .AddEntityFrameworkStores <SampekeyDbContex>() .AddDefaultTokenProviders(); services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme).AddJwtBearer(options => options.TokenValidationParameters = SampekeyParams.GetTokenValidationParameters()); services.AddTransient <IAccount, AccountRepo>(); services.AddTransient <IEnviroment, EnviromentRepo>(); services.AddTransient <IEsrp, EsrpRepo>(); services.AddTransient <IModule, ModuleRepo>(); services.AddTransient <IPermission, PermissionRepo>(); services.AddTransient <IRole, RoleRepo>(); services.AddTransient <ISystem, SystemRepo>(); services.AddTransient <ISystemModule, SystemModuleRepo>(); services.AddTransient <IUser, UserRepo>(); services.AddCors(options => { options.AddPolicy("CorsPolicy", builder => builder.AllowAnyOrigin() .AllowAnyMethod() .AllowAnyHeader() ); }); services.AddSwaggerGen(c => { c.SwaggerDoc("v1", new OpenApiInfo { Title = "KEYCATCH API", Version = "v1" }); c.AddSecurityDefinition("Bearer", new OpenApiSecurityScheme { Description = "JWT Authorization header using the Bearer scheme. \r\n\r\n Enter 'Bearer' [space] and then your token in the text input below.\r\n\r\nExample: \"Bearer 12345abcdef\"", Name = "Authorization", In = ParameterLocation.Header, Type = SecuritySchemeType.ApiKey, Scheme = "Bearer" }); c.AddSecurityRequirement(new OpenApiSecurityRequirement() { { new OpenApiSecurityScheme { Reference = new OpenApiReference { Type = ReferenceType.SecurityScheme, Id = "Bearer" }, Scheme = "oauth2", Name = "Bearer", In = ParameterLocation.Header, }, new List <string>() } }); }); }