aboutsummaryrefslogtreecommitdiff
path: root/src/Common/DevHive.Common
diff options
context:
space:
mode:
authortranstrike <transtrike@gmail.com>2021-02-28 13:00:16 +0200
committertranstrike <transtrike@gmail.com>2021-02-28 13:00:16 +0200
commit26b18fe3727507d1b47ffb53ed773f133122eee8 (patch)
treecad0cdb64cd98edf1ced707b2296fb16da505801 /src/Common/DevHive.Common
parente4331fe503547df8f17095540cbd4170bbaf2b25 (diff)
downloadDevHive-26b18fe3727507d1b47ffb53ed773f133122eee8.tar
DevHive-26b18fe3727507d1b47ffb53ed773f133122eee8.tar.gz
DevHive-26b18fe3727507d1b47ffb53ed773f133122eee8.zip
Integrated new JWT validation where needed
Diffstat (limited to 'src/Common/DevHive.Common')
-rw-r--r--src/Common/DevHive.Common/Jwt/Interfaces/IJwtService.cs17
-rw-r--r--src/Common/DevHive.Common/Jwt/JwtService.cs2
2 files changed, 17 insertions, 2 deletions
diff --git a/src/Common/DevHive.Common/Jwt/Interfaces/IJwtService.cs b/src/Common/DevHive.Common/Jwt/Interfaces/IJwtService.cs
index 6f844f5..352a7d5 100644
--- a/src/Common/DevHive.Common/Jwt/Interfaces/IJwtService.cs
+++ b/src/Common/DevHive.Common/Jwt/Interfaces/IJwtService.cs
@@ -5,7 +5,24 @@ namespace DevHive.Common.Jwt.Interfaces
{
public interface IJwtService
{
+ /// <summary>
+ /// The generation of a JWT, when a new user registers or log ins
+ /// Tokens have an expiration time of 7 days.
+ /// </summary>
+ /// <param name="userId">User's Guid</param>
+ /// <param name="username">Users's username</param>
+ /// <param name="roleNames">List of user's roles</param>
+ /// <returns>Return a new JWT, containing the user id, username and roles.</returns>
string GenerateJwtToken(Guid userId, string username, List<string> roleNames);
+
+ /// <summary>
+ /// Checks whether the given user, gotten by the "id" property,
+ /// is the same user as the one in the token (unless the user in the token has the admin role)
+ /// and the roles in the token are the same as those in the user, gotten by the id in the token
+ /// </summary>
+ /// <param name="userId">Guid of the user being validated</param>
+ /// <param name="rawToken">The raw token coming from the request</param>
+ /// <returns>Bool result of is the user authenticated to do an action</returns>
bool ValidateToken(Guid userId, string rawToken);
}
}
diff --git a/src/Common/DevHive.Common/Jwt/JwtService.cs b/src/Common/DevHive.Common/Jwt/JwtService.cs
index a0c49db..9f316da 100644
--- a/src/Common/DevHive.Common/Jwt/JwtService.cs
+++ b/src/Common/DevHive.Common/Jwt/JwtService.cs
@@ -1,11 +1,9 @@
using System;
-using System.Buffers.Text;
using System.Collections.Generic;
using System.IdentityModel.Tokens.Jwt;
using System.Linq;
using System.Security.Claims;
using System.Security.Principal;
-using System.Text;
using DevHive.Common.Jwt.Interfaces;
using Microsoft.IdentityModel.Tokens;