Skip to content

Commit

Permalink
JWT Implemented
Browse files Browse the repository at this point in the history
  • Loading branch information
rahiyansafz committed Jun 22, 2022
1 parent d2f1178 commit d1244c3
Show file tree
Hide file tree
Showing 19 changed files with 393 additions and 1,282 deletions.
16 changes: 3 additions & 13 deletions Hotels.API/Controllers/AccountController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,22 +50,12 @@ public async Task<ActionResult> Register([FromBody] UserDto userDto)
public async Task<ActionResult> Login([FromBody] LoginDto login)
{
//_logger.LogInformation($"Login Attempt for {loginDto.Email} ");
//var authResponse = await _authManager.Login(login);
var authResponse = await _authManager.Login(login);

//if (authResponse == null)
//{
// return Unauthorized();
//}

//return Ok(authResponse);

var isValidUser = await _authManager.Login(login);

if (!isValidUser)
if (authResponse is null)
return Unauthorized();

return Ok();

return Ok(authResponse);
}

//// POST: api/Account/refreshtoken
Expand Down
1 change: 1 addition & 0 deletions Hotels.API/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using Hotels.DataAccess.Repository;
using Hotels.Models.Configurations;
using Hotels.Models.Models;
using Hotels.Models.Models.Auth;
using Microsoft.AspNetCore.Authentication.JwtBearer;
using Microsoft.AspNetCore.Identity;
using Microsoft.EntityFrameworkCore;
Expand Down
2 changes: 1 addition & 1 deletion Hotels.API/appsettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"Issuer": "HotelsAPI",
"Audience": "HotelsAPIClient",
"DurationInMinutes": 60,
"Key": "YourSuperSecretKey"
"Key": "ecba7c69-031f-4bee-8294-118fdef62730"
},
"Serilog": {
"MinimumLevel": {
Expand Down
4 changes: 3 additions & 1 deletion Hotels.DataAccess/Contracts/IAuthManager.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
using Hotels.Models.Dtos.User;
using Hotels.Models.Models;
using Hotels.Models.Models.Auth;
using Microsoft.AspNetCore.Identity;

namespace Hotels.DataAccess.Contracts;

public interface IAuthManager
{
Task<IEnumerable<IdentityError>> Register(UserDto user);
Task<bool> Login(LoginDto login);
Task<AuthResponse> Login(LoginDto login);
}
1 change: 1 addition & 0 deletions Hotels.DataAccess/Data/DataContext.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using Hotels.DataAccess.Data.Configurations;
using Hotels.Models.Models;
using Hotels.Models.Models.Auth;
using Microsoft.AspNetCore.Identity.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore;

Expand Down
317 changes: 0 additions & 317 deletions Hotels.DataAccess/Migrations/20220621212948_InitialDb.Designer.cs

This file was deleted.

Loading

0 comments on commit d1244c3

Please sign in to comment.