Skip to content

Commit 44ed0b6

Browse files
Merge pull request #126 from nullinside-development-group/feat/oauth
feat: adding refresh token and expiring for oauth
2 parents 76a3c69 + 8929b87 commit 44ed0b6

File tree

10 files changed

+418
-22
lines changed

10 files changed

+418
-22
lines changed

src/Nullinside.Api.Common.AspNetCore/Middleware/BasicAuthenticationHandler.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,8 @@ protected override async Task<AuthenticateResult> HandleAuthenticateAsync() {
6161
.AsNoTracking()
6262
.FirstOrDefaultAsync(u => !string.IsNullOrWhiteSpace(u.Token) &&
6363
u.Token == token &&
64-
!u.IsBanned).ConfigureAwait(false);
64+
!u.IsBanned)
65+
.ConfigureAwait(false);
6566

6667
if (null == dbUser) {
6768
return AuthenticateResult.Fail("Invalid token");

src/Nullinside.Api.Common/Auth/AuthUtils.cs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,10 @@ namespace Nullinside.Api.Common.Auth;
77
/// </summary>
88
public static class AuthUtils {
99
/// <summary>
10-
/// Generates a new unique bearer token.
10+
/// Generates a new unique token.
1111
/// </summary>
12-
/// <returns>A bearer token.</returns>
13-
public static string GenerateBearerToken() {
14-
// This method is trash but it doesn't matter. We should be doing real OAuth tokens with expirations and
15-
// renewals. Right now nothing that exists on the site requires this level of sophistication.
12+
/// <returns>A token.</returns>
13+
public static string GenerateToken() {
1614
string allowed = "ABCDEFGHIJKLMONOPQRSTUVWXYZabcdefghijklmonopqrstuvwxyz0123456789";
1715
int strlen = 255; // Or whatever
1816
char[] randomChars = new char[strlen];

src/Nullinside.Api.Model/Ddl/User.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,16 @@ public class User : ITableModel {
2727
/// The user's auth token for interacting with the site's API.
2828
/// </summary>
2929
public string? Token { get; set; }
30+
31+
/// <summary>
32+
/// The user's auth token for interacting with the site's API.
33+
/// </summary>
34+
public string? RefreshToken { get; set; }
35+
36+
/// <summary>
37+
/// The user's auth token for interacting with the site's API.
38+
/// </summary>
39+
public DateTime? TokenExpires { get; set; }
3040

3141
/// <summary>
3242
/// The id of the user on twitch.
@@ -95,6 +105,8 @@ public void OnModelCreating(ModelBuilder modelBuilder) {
95105
.HasMaxLength(255);
96106
entity.Property(e => e.Token)
97107
.HasMaxLength(255);
108+
entity.Property(e => e.RefreshToken)
109+
.HasMaxLength(255);
98110
entity.Property(e => e.UpdatedOn)
99111
.IsRowVersion();
100112
// TODO: Add the other strings in this file with lengths

src/Nullinside.Api.Model/Migrations/20250930224533_OAuthRefreshToken.Designer.cs

Lines changed: 321 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)