Skip to content

Commit bb4381b

Browse files
author
Oyvind Timian Dokk Husveg
committed
Working on variable token lifespan
1 parent e06fece commit bb4381b

File tree

2 files changed

+6
-15
lines changed

2 files changed

+6
-15
lines changed

exercise.wwwapi/DTOs/Login/LoginRequestDTO.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,6 @@ public class LoginRequestDTO
77
{
88
public string? email { get; set; }
99
public string? password { get; set; }
10+
public bool? longlifetoken { get; set; }
1011
}
1112
}

exercise.wwwapi/Endpoints/UserEndpoints.cs

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ public static class UserEndpoints
2222
public static void ConfigureAuthApi(this WebApplication app)
2323
{
2424
app.MapPost("/login", Login).WithSummary("Localhost Login");
25-
app.MapGet("/me", Me).WithSummary("Return user associated with token");
2625

2726
var users = app.MapGroup("users");
2827
users.MapPost("/", Register).WithSummary("Create user");
@@ -32,19 +31,6 @@ public static void ConfigureAuthApi(this WebApplication app)
3231

3332
}
3433

35-
[Authorize]
36-
[ProducesResponseType(StatusCodes.Status200OK)]
37-
private static IResult Me(IRepository<User> repository, IMapper mapper, ClaimsPrincipal claims)
38-
{
39-
int? id = claims.UserRealId();
40-
User? user = repository.GetById(id);
41-
if (user == null) {
42-
return TypedResults.BadRequest();
43-
}
44-
//UserDTO userDTO = Mapper.Map<UserDTO>(user);
45-
return TypedResults.Ok();
46-
}
47-
4834
/// <summary>
4935
/// Retrieves users, optionally filtered by a case-insensitive search on first name, last name, or full name.
5036
/// </summary>
@@ -156,7 +142,11 @@ private static IResult Login(IRepository<User> repository, IMapper mapper, Login
156142
return Results.BadRequest(new ResponseDTO<Object>() { Message = "Invalid email and/or password provided" });
157143
}
158144

159-
string token = CreateToken(user, config);
145+
string token;
146+
token = CreateToken(user, config);
147+
//if (request.longlifetoken != null && request.longlifetoken) token = CreateToken(user, config);
148+
//else token = CreateToken(user, config);
149+
160150

161151
ResponseDTO<LoginSuccessDTO> response = new ResponseDTO<LoginSuccessDTO>
162152
{

0 commit comments

Comments
 (0)