From 9ef232ba29fd42c856c51fe7ae1b1765dcc498ea Mon Sep 17 00:00:00 2001 From: vnugent Date: Mon, 2 Sep 2024 01:30:23 -0400 Subject: push pending changes --- .../src/Endpoints/AccessTokenEndpoint.cs | 40 +++++++++++++++------- .../src/OauthTokenResponseMessage.cs | 6 +++- 2 files changed, 32 insertions(+), 14 deletions(-) diff --git a/libs/VNLib.Plugins.Sessions.OAuth/src/Endpoints/AccessTokenEndpoint.cs b/libs/VNLib.Plugins.Sessions.OAuth/src/Endpoints/AccessTokenEndpoint.cs index ef5ff5c..c251212 100644 --- a/libs/VNLib.Plugins.Sessions.OAuth/src/Endpoints/AccessTokenEndpoint.cs +++ b/libs/VNLib.Plugins.Sessions.OAuth/src/Endpoints/AccessTokenEndpoint.cs @@ -56,15 +56,19 @@ namespace VNLib.Plugins.Sessions.OAuth.Endpoints DisableSessionsRequired = true }; - public AccessTokenEndpoint(PluginBase pbase, IConfigScope config, IApplicationTokenFactory tokenFactory) + public AccessTokenEndpoint(PluginBase plugin, IConfigScope config, IApplicationTokenFactory tokenFactory) { - string? path = config.GetRequiredProperty("token_path", p => p.GetString()!); - - InitPathAndLog(path, pbase.Log); + InitPathAndLog( + path: config.GetRequiredProperty("token_path"), + log: plugin.Log.CreateScope("Token Endpoint") + ); TokenFactory = tokenFactory; - Applications = new(pbase.GetContextOptions(), pbase.GetOrCreateSingleton()); + Applications = new( + plugin.GetContextOptions(), + plugin.GetOrCreateSingleton() + ); } @@ -121,7 +125,12 @@ namespace VNLib.Plugins.Sessions.OAuth.Endpoints if (app is null) { //App was not found or the credentials do not match - entity.CloseResponseError(HttpStatusCode.UnprocessableEntity, ErrorType.InvalidClient, "The credentials are invalid or do not exist"); + entity.CloseResponseError( + HttpStatusCode.UnprocessableEntity, + ErrorType.InvalidClient, + description: "The credentials are invalid or do not exist" + ); + return VfReturnType.VirtualSkip; } @@ -129,19 +138,24 @@ namespace VNLib.Plugins.Sessions.OAuth.Endpoints if (result is null) { - entity.CloseResponseError(HttpStatusCode.TooManyRequests, ErrorType.TemporarilyUnavailable, "You have reached the maximum number of valid tokens for this application"); + entity.CloseResponseError( + HttpStatusCode.TooManyRequests, + ErrorType.TemporarilyUnavailable, + description: "You have reached the maximum number of valid tokens for this application" + ); + return VfReturnType.VirtualSkip; } //Create the new response message OauthTokenResponseMessage tokenMessage = new() { - AccessToken = result.AccessToken, - IdToken = result.IdentityToken, - //set expired as seconds in int form - Expires = result.ExpiresSeconds, - RefreshToken = result.RefreshToken, - TokenType = result.TokenType + //set expired as seconds in int form + Expires = result.ExpiresSeconds, + AccessToken = result.AccessToken, + IdToken = result.IdentityToken, + RefreshToken = result.RefreshToken, + TokenType = result.TokenType }; //Respond with the token message diff --git a/libs/VNLib.Plugins.Sessions.OAuth/src/OauthTokenResponseMessage.cs b/libs/VNLib.Plugins.Sessions.OAuth/src/OauthTokenResponseMessage.cs index 2a063b0..8241663 100644 --- a/libs/VNLib.Plugins.Sessions.OAuth/src/OauthTokenResponseMessage.cs +++ b/libs/VNLib.Plugins.Sessions.OAuth/src/OauthTokenResponseMessage.cs @@ -1,5 +1,5 @@ /* -* Copyright (c) 2022 Vaughn Nugent +* Copyright (c) 2024 Vaughn Nugent * * Library: VNLib * Package: VNLib.Plugins.Essentials.Sessions.OAuth @@ -30,12 +30,16 @@ namespace VNLib.Plugins.Sessions.OAuth { [JsonPropertyName("access_token")] public string? AccessToken { get; set; } + [JsonPropertyName("refresh_token")] public string? RefreshToken { get; set; } + [JsonPropertyName("token_type")] public string? TokenType { get; set; } + [JsonPropertyName("expires_in")] public int Expires { get; set; } + [JsonPropertyName("id_token")] public string? IdToken { get; set; } } -- cgit