diff options
| author | Ognjen Cirkovic <ciraboxkg@gmail.com> | 2022-03-21 17:30:57 +0100 | 
|---|---|---|
| committer | Ognjen Cirkovic <ciraboxkg@gmail.com> | 2022-03-21 17:30:57 +0100 | 
| commit | 72564a9d2d6b9c7f4be8e786fadd40ce9248c7c1 (patch) | |
| tree | dd6a48606aa03132ba66452869f6c28fb0d3d23d /backend | |
| parent | 3f4b29011e2f525bd8c2bd81a1dd5f8f741d1de3 (diff) | |
Omoguceno preuzimaje guest Tokena.
Diffstat (limited to 'backend')
| -rw-r--r-- | backend/api/api/Controllers/AuthController.cs | 6 | ||||
| -rw-r--r-- | backend/api/api/Models/JwtToken.cs | 16 | ||||
| -rw-r--r-- | backend/api/api/Services/AuthService.cs | 5 | ||||
| -rw-r--r-- | backend/api/api/Services/IAuthService.cs | 1 | 
4 files changed, 28 insertions, 0 deletions
| diff --git a/backend/api/api/Controllers/AuthController.cs b/backend/api/api/Controllers/AuthController.cs index 7167d1bf..901454e1 100644 --- a/backend/api/api/Controllers/AuthController.cs +++ b/backend/api/api/Controllers/AuthController.cs @@ -30,6 +30,12 @@ namespace api.Controllers              return Ok(_auth.Login(user));          } +        [HttpPost("guestToken")] +        public async Task<ActionResult<string>> guestToken() +        { + +            return Ok(_auth.GuestToken()); +        }          [HttpGet("Auth")]          [Authorize(Roles ="User")] diff --git a/backend/api/api/Models/JwtToken.cs b/backend/api/api/Models/JwtToken.cs index a98d1967..f262fd23 100644 --- a/backend/api/api/Models/JwtToken.cs +++ b/backend/api/api/Models/JwtToken.cs @@ -69,6 +69,22 @@ namespace api.Models          } +        public string GenGuestToken() +        { +            var tokenHandler = new JwtSecurityTokenHandler(); +            var key = Encoding.ASCII.GetBytes(_configuration.GetSection("AppSettings:JwtToken").Value); +            var tokenDescriptor = new SecurityTokenDescriptor +            { +                Subject = new ClaimsIdentity(new[] { new Claim("name",""), +                                                    new Claim("role", "Guest")}), +                Expires = DateTime.UtcNow.AddMinutes(20), +                SigningCredentials = new SigningCredentials(new SymmetricSecurityKey(key), SecurityAlgorithms.HmacSha256Signature) +            }; +            var token = tokenHandler.CreateToken(tokenDescriptor); +            return tokenHandler.WriteToken(token); + +        } +      } diff --git a/backend/api/api/Services/AuthService.cs b/backend/api/api/Services/AuthService.cs index 4f838463..8ef96e2e 100644 --- a/backend/api/api/Services/AuthService.cs +++ b/backend/api/api/Services/AuthService.cs @@ -57,6 +57,11 @@ namespace api.Services              return null;          } +        public string GuestToken() +        { +            return _jwt.GenGuestToken(); +        } +      }  } diff --git a/backend/api/api/Services/IAuthService.cs b/backend/api/api/Services/IAuthService.cs index 591d122d..9a109208 100644 --- a/backend/api/api/Services/IAuthService.cs +++ b/backend/api/api/Services/IAuthService.cs @@ -7,5 +7,6 @@ namespace api.Services          string Login(AuthRequest user);          string Register(RegisterRequest user);          string RenewToken(string token); +        public string GuestToken();      }  }
\ No newline at end of file | 
