Beging to add the authorization with a JWT token

This commit is contained in:
Sébastien André
2020-03-19 21:33:09 +01:00
parent 170ccbd9c5
commit 7bb702e46c
9 changed files with 132 additions and 17 deletions

View File

@@ -1,6 +1,8 @@
using System.Collections.Generic;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Cors;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Authentication.JwtBearer;
using AutoMapper;
@@ -13,6 +15,7 @@ namespace skydiveLogs_api.Controllers
{
[Route("api/[controller]")]
[ApiController]
[Authorize(AuthenticationSchemes = JwtBearerDefaults.AuthenticationScheme)]
public class JumpController : ControllerBase
{
public JumpController(IJumpService jumpService,
@@ -27,7 +30,9 @@ namespace skydiveLogs_api.Controllers
[EnableCors]
public IEnumerable<JumpResp> Get()
{
var result = _jumpService.GetAllJumps();
var connectedUser = new User() { Id = 1 }; // TEST
var result = _jumpService.GetAllJumps(connectedUser);
return _mapper.Map<IEnumerable<JumpResp>>(result);
}
@@ -49,7 +54,8 @@ namespace skydiveLogs_api.Controllers
value.DropZoneId,
value.JumpTypeId,
value.GearId,
_mapper.Map<Jump>(value));
_mapper.Map<Jump>(value),
null /* Provenant du token */);
}
// PUT: api/Jump/5