Foxchat.NET/Foxchat.Identity/Utils/OauthUtils.cs

35 lines
No EOL
989 B
C#

using Foxchat.Core;
using Foxchat.Identity.Middleware;
using Foxchat.Identity.Database.Models;
namespace Foxchat.Identity.Utils;
public static class OauthUtils
{
public static readonly string[] Scopes = ["identify", "chat_client"];
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;
}
}
public static string[] ExpandScopes(this Token token) => token.Scopes.Contains("chat_client")
? Scopes
: token.Scopes;
public static string[] ExpandScopes(this Application app) => app.Scopes.Contains("chat_client")
? Scopes
: app.Scopes;
}