2024-05-20 19:42:04 +02:00
|
|
|
using Foxchat.Core;
|
|
|
|
using Foxchat.Identity.Middleware;
|
|
|
|
using Foxchat.Identity.Database.Models;
|
|
|
|
|
2024-05-20 17:00:21 +02:00
|
|
|
namespace Foxchat.Identity.Utils;
|
|
|
|
|
|
|
|
public static class OauthUtils
|
|
|
|
{
|
2024-05-22 17:19:45 +02:00
|
|
|
public const string ClientCredentials = "client_credentials";
|
|
|
|
public const string AuthorizationCode = "authorization_code";
|
|
|
|
|
|
|
|
public static readonly string[] Scopes = ["identify", "email", "guilds", "chat_client"];
|
2024-05-20 17:00:21 +02:00
|
|
|
|
|
|
|
private static readonly string[] ForbiddenSchemes = ["javascript", "file", "data", "mailto", "tel"];
|
|
|
|
private const string OobUri = "urn:ietf:wg:oauth:2.0:oob";
|
|
|
|
|
|
|
|
public static bool ValidateRedirectUri(string uri)
|
|
|
|
{
|
|
|
|
if (uri == OobUri) return true;
|
|
|
|
try
|
|
|
|
{
|
|
|
|
var scheme = new Uri(uri).Scheme;
|
|
|
|
return !ForbiddenSchemes.Contains(scheme);
|
|
|
|
}
|
|
|
|
catch
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2024-05-21 21:21:34 +02:00
|
|
|
|
2024-05-22 17:19:45 +02:00
|
|
|
public static string[] ExpandScopes(this string[] scopes) => scopes.Contains("chat_client")
|
2024-05-21 21:21:34 +02:00
|
|
|
? Scopes
|
2024-05-22 17:19:45 +02:00
|
|
|
: scopes;
|
2024-05-21 21:21:34 +02:00
|
|
|
}
|