Skip to content

Commit 1218d7b

Browse files
authored
init
1 parent 49a25a4 commit 1218d7b

File tree

5 files changed

+89
-19
lines changed

5 files changed

+89
-19
lines changed

Common/RSAKeyHelper.cs

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
using System.Security.Cryptography;
2+
3+
4+
namespace ASPNETCoreAngularJWT
5+
{
6+
public class RSAKeyHelper
7+
{
8+
public static RSAParameters GenerateKey()
9+
{
10+
using (var key = new RSACryptoServiceProvider(2048))
11+
{
12+
return key.ExportParameters(true);
13+
}
14+
}
15+
}
16+
}

Common/RequestResult.cs

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
using System;
2+
3+
4+
namespace ASPNETCoreAngularJWT
5+
{
6+
public class RequestResult
7+
{
8+
public RequestState State { get; set; }
9+
public string Msg { get; set; }
10+
public Object Data { get; set; }
11+
}
12+
13+
public enum RequestState
14+
{
15+
Failed = -1,
16+
NotAuth = 0,
17+
Success = 1
18+
}
19+
}

Common/TokenAuthOption.cs

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
using Microsoft.IdentityModel.Tokens;
2+
using System;
3+
4+
5+
6+
namespace ASPNETCoreAngularJWT
7+
{
8+
public class TokenAuthOption
9+
{
10+
public static string Audience { get; } = "MyAudience";
11+
public static string Issuer { get; } = "MyIssuer";
12+
public static RsaSecurityKey Key { get; } = new RsaSecurityKey(RSAKeyHelper.GenerateKey());
13+
public static SigningCredentials SigningCredentials { get; } = new SigningCredentials(Key, SecurityAlgorithms.RsaSha256Signature);
14+
15+
public static TimeSpan ExpiresSpan { get; } = TimeSpan.FromMinutes(40);
16+
public static string TokenType { get; } = "Bearer";
17+
}
18+
19+
}

Common/User.cs

+20-19
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,20 @@
1-
using System;
2-
3-
4-
namespace ASPNETCoreAngularJWT
5-
{
6-
public class User
7-
{
8-
public Guid ID { get; set; }
9-
public string Username { get; set; }
10-
11-
public string Password { get; set; }
12-
13-
public string Fname {get;set;}
14-
public string Lname {get;set;}
15-
16-
}
17-
18-
19-
}
1+
using System;
2+
3+
4+
5+
namespace ASPNETCoreAngularJWT
6+
{
7+
public class User
8+
{
9+
public Guid ID { get; set; }
10+
public string Username { get; set; }
11+
12+
public string Password { get; set; }
13+
14+
public string Fname {get;set;}
15+
public string Lname {get;set;}
16+
17+
}
18+
19+
20+
}

Common/UserStorage.cs

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
using System;
2+
using System.Collections.Generic;
3+
4+
namespace ASPNETCoreAngularJWT
5+
{
6+
public static class UserStorage
7+
{
8+
public static List<User> Users { get; set; } = new List<User> {
9+
new User {ID=Guid.NewGuid(),Username="user1",Password = "user1psd", Fname="user1", Lname="Lname1" },
10+
new User {ID=Guid.NewGuid(),Username="user2",Password = "user2psd", Fname="user2", Lname="Lname2" },
11+
new User {ID=Guid.NewGuid(),Username="user3",Password = "user3psd", Fname="user3", Lname="Lname3" }
12+
};
13+
14+
}
15+
}

0 commit comments

Comments
 (0)