mirror of
https://github.com/tgstation/tgstation-server.git
synced 2026-08-27 07:04:57 +01:00
Merge pull request #1370 from tgstation/aa/invision-auth
Invision Community OAuth Support
This commit is contained in:
+2
-2
@@ -4,8 +4,8 @@
|
||||
<Import Project="ControlPanelVersion.props" />
|
||||
<PropertyGroup>
|
||||
<TgsCoreVersion>4.17.1</TgsCoreVersion>
|
||||
<TgsConfigVersion>4.1.0</TgsConfigVersion>
|
||||
<TgsApiVersion>9.4.0</TgsApiVersion>
|
||||
<TgsConfigVersion>4.2.0</TgsConfigVersion>
|
||||
<TgsApiVersion>9.5.0</TgsApiVersion>
|
||||
<TgsApiLibraryVersion>9.4.0</TgsApiLibraryVersion>
|
||||
<TgsClientVersion>10.5.0</TgsClientVersion>
|
||||
<TgsDmapiVersion>6.0.5</TgsDmapiVersion>
|
||||
|
||||
@@ -28,5 +28,10 @@ namespace Tgstation.Server.Api.Models
|
||||
/// https://www.keycloak.org
|
||||
/// </summary>
|
||||
Keycloak,
|
||||
|
||||
/// <summary>
|
||||
/// https://invisioncommunity.com/
|
||||
/// </summary>
|
||||
InvisionCommunity,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,51 @@
|
||||
using System;
|
||||
using System.Net.Http;
|
||||
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
using Tgstation.Server.Api.Models;
|
||||
using Tgstation.Server.Host.Configuration;
|
||||
using Tgstation.Server.Host.System;
|
||||
|
||||
namespace Tgstation.Server.Host.Security.OAuth
|
||||
{
|
||||
/// <summary>
|
||||
/// OAuth validator for Invision Community (selfhosted).
|
||||
/// </summary>
|
||||
sealed class InvisionCommunityOAuthValidator : GenericOAuthValidator
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public override OAuthProvider Provider => OAuthProvider.InvisionCommunity;
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override Uri TokenUrl => new Uri($"{OAuthConfiguration.ServerUrl}/oauth/token/"); // This needs the trailing slash or it doesnt get the token. Do not remove.
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override Uri UserInformationUrl => new Uri($"{OAuthConfiguration.ServerUrl}/api/core/me");
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="InvisionCommunityOAuthValidator"/> class.
|
||||
/// </summary>
|
||||
/// <param name="httpClientFactory">The <see cref="IHttpClientFactory"/> for the <see cref="GenericOAuthValidator"/>.</param>
|
||||
/// <param name="assemblyInformationProvider">The <see cref="IAssemblyInformationProvider"/> for the <see cref="GenericOAuthValidator"/>.</param>
|
||||
/// <param name="logger">The <see cref="ILogger"/> for the <see cref="GenericOAuthValidator"/>.</param>
|
||||
/// <param name="oAuthConfiguration">The <see cref="OAuthConfiguration"/> for the <see cref="GenericOAuthValidator"/>.</param>
|
||||
public InvisionCommunityOAuthValidator(
|
||||
IHttpClientFactory httpClientFactory,
|
||||
IAssemblyInformationProvider assemblyInformationProvider,
|
||||
ILogger<InvisionCommunityOAuthValidator> logger,
|
||||
OAuthConfiguration oAuthConfiguration)
|
||||
: base(httpClientFactory, assemblyInformationProvider, logger, oAuthConfiguration)
|
||||
{
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override OAuthTokenRequest CreateTokenRequest(string code) => new OAuthTokenRequest(OAuthConfiguration, code, "profile");
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override string DecodeTokenPayload(dynamic responseJson) => responseJson.access_token;
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override string DecodeUserInformationPayload(dynamic responseJson) => responseJson.id;
|
||||
}
|
||||
}
|
||||
@@ -79,6 +79,14 @@ namespace Tgstation.Server.Host.Security.OAuth
|
||||
assemblyInformationProvider,
|
||||
loggerFactory.CreateLogger<KeycloakOAuthValidator>(),
|
||||
keyCloakConfig));
|
||||
|
||||
if (securityConfiguration.OAuth.TryGetValue(OAuthProvider.InvisionCommunity, out var invisionConfig))
|
||||
validatorsBuilder.Add(
|
||||
new InvisionCommunityOAuthValidator(
|
||||
httpClientFactory,
|
||||
assemblyInformationProvider,
|
||||
loggerFactory.CreateLogger<InvisionCommunityOAuthValidator>(),
|
||||
invisionConfig));
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
|
||||
Reference in New Issue
Block a user