Skip to content

Commit

Permalink
v1.2 (#15)
Browse files Browse the repository at this point in the history
  • Loading branch information
Hawxy authored Apr 9, 2024
1 parent 41e0934 commit d25507f
Show file tree
Hide file tree
Showing 9 changed files with 54 additions and 19 deletions.
2 changes: 1 addition & 1 deletion Package.Build.props
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project>
<PropertyGroup>
<Version>1.1.0</Version>
<Version>1.2.0</Version>
<Authors>Hawxy</Authors>
<PackageRequireLicenseAcceptance>true</PackageRequireLicenseAcceptance>
<PackageLicenseExpression>Apache-2.0</PackageLicenseExpression>
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ builder.Services.AddOpenFgaClient(config =>
{
config.ConfigureAuth0Fga(x =>
{
// Change to EU/AUS depending on where your store is located
x.SetEnvironment(FgaEnvironment.US);
x.WithAuthentication(builder.Configuration["Auth0Fga:ClientId"]!, builder.Configuration["Auth0Fga:ClientSecret"]!);
});

Expand Down
4 changes: 2 additions & 2 deletions build/_build.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net7.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<RootNamespace></RootNamespace>
<NoWarn>CS0649;CS0169</NoWarn>
<NukeRootDirectory>..</NukeRootDirectory>
Expand All @@ -11,7 +11,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Nuke.Common" Version="7.0.6" />
<PackageReference Include="Nuke.Common" Version="8.0.0" />
</ItemGroup>

</Project>
5 changes: 4 additions & 1 deletion build/_build.csproj.DotSettings
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
<s:Boolean x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/PLACE_SIMPLE_ANONYMOUSMETHOD_ON_SINGLE_LINE/@EntryValue">False</s:Boolean>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/PredefinedNamingRules/=PrivateInstanceFields/@EntryIndexedValue">&lt;Policy Inspect="True" Prefix="" Suffix="" Style="AaBb" /&gt;</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/PredefinedNamingRules/=PrivateStaticFields/@EntryIndexedValue">&lt;Policy Inspect="True" Prefix="" Suffix="" Style="AaBb" /&gt;</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/UserRules/=4a98fdf6_002D7d98_002D4f5a_002Dafeb_002Dea44ad98c70c/@EntryIndexedValue">&lt;Policy&gt;&lt;Descriptor Staticness="Instance" AccessRightKinds="Private" Description="Instance fields (private)"&gt;&lt;ElementKinds&gt;&lt;Kind Name="FIELD" /&gt;&lt;Kind Name="READONLY_FIELD" /&gt;&lt;/ElementKinds&gt;&lt;/Descriptor&gt;&lt;Policy Inspect="True" Prefix="" Suffix="" Style="AaBb" /&gt;&lt;/Policy&gt;</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/UserRules/=f9fce829_002De6f4_002D4cb2_002D80f1_002D5497c44f51df/@EntryIndexedValue">&lt;Policy&gt;&lt;Descriptor Staticness="Static" AccessRightKinds="Private" Description="Static fields (private)"&gt;&lt;ElementKinds&gt;&lt;Kind Name="FIELD" /&gt;&lt;/ElementKinds&gt;&lt;/Descriptor&gt;&lt;Policy Inspect="True" Prefix="" Suffix="" Style="AaBb" /&gt;&lt;/Policy&gt;</s:String>
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ECSharpAttributeForSingleLineMethodUpgrade/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ECSharpKeepExistingMigration/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ECSharpPlaceEmbeddedOnSameLineMigration/@EntryIndexedValue">True</s:Boolean>
Expand All @@ -24,4 +26,5 @@
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ESettingsUpgrade_002EAddAccessorOwnerDeclarationBracesMigration/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ESettingsUpgrade_002ECSharpPlaceAttributeOnSameLineMigration/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ESettingsUpgrade_002EMigrateBlankLinesAroundFieldToBlankLinesAroundProperty/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ESettingsUpgrade_002EMigrateThisQualifierSettings/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary>
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ESettingsUpgrade_002EMigrateThisQualifierSettings/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ESettingsUpgrade_002EPredefinedNamingRulesToUserRulesUpgrade/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary>
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ protected override async Task HandleRequirementAsync(AuthorizationHandlerContext

var endpoint = httpContext.GetEndpoint();
if (endpoint is null)
return;
throw new InvalidOperationException($"{nameof(FineGrainedAuthorizationHandler)} was unable to resolve the current endpoint. This handler is only compatible with endpoint routing.");

var attributes = endpoint.Metadata.GetOrderedMetadata<FgaAttribute>();
// The user is enforcing the fga policy but there's no attributes here.
if (attributes.Count == 0)
Expand Down
46 changes: 37 additions & 9 deletions src/Fga.Net/Configuration/Auth0FgaConnectionBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,20 @@ namespace Fga.Net.DependencyInjection.Configuration;
/// <summary>
/// Available environments for Auth0 FGA
/// </summary>
public enum Auth0Environment
public enum FgaEnvironment
{
/// <summary>
/// US Environment - `fga.us.auth0.com`
/// US Environment - `api.us1.fga.dev`
/// </summary>
Us
US,
/// <summary>
/// AU Environment - `api.au1.fga.dev`
/// </summary>
AU,
/// <summary>
/// EU Environment - `api.eu1.fga.dev`
/// </summary>
EU
}

internal sealed record Auth0FgaEnvironment(string ApiHost, string ApiTokenIssuer, string ApiAudience);
Expand All @@ -40,33 +48,53 @@ internal sealed record Auth0FgaEnvironment(string ApiHost, string ApiTokenIssuer
/// </summary>
public sealed class Auth0FgaConnectionBuilder
{
private readonly IReadOnlyDictionary<Auth0Environment, Auth0FgaEnvironment> _fgaEnvironments =
new Dictionary<Auth0Environment, Auth0FgaEnvironment>()
private const string FgaIssuer = "fga.us.auth0.com";

private readonly IReadOnlyDictionary<FgaEnvironment, Auth0FgaEnvironment> _fgaEnvironments =
new Dictionary<FgaEnvironment, Auth0FgaEnvironment>()
{
{
Auth0Environment.Us,
new Auth0FgaEnvironment("https://api.us1.fga.dev", "fga.us.auth0.com", "https://api.us1.fga.dev/")
FgaEnvironment.US,
new Auth0FgaEnvironment("https://api.us1.fga.dev", FgaIssuer, "https://api.us1.fga.dev/")
},
{
FgaEnvironment.EU,
new Auth0FgaEnvironment("https://api.eu1.fga.dev", FgaIssuer, "https://api.eu1.fga.dev/")
},
{
FgaEnvironment.AU,
new Auth0FgaEnvironment("https://api.au1.fga.dev", FgaIssuer, "https://api.au1.fga.dev/")
}
};

private readonly Auth0Environment _environment = Auth0Environment.Us;
private FgaEnvironment _environment = FgaEnvironment.US;

private string _clientId = null!;
private string _clientSecret = null!;

/// <summary>
/// Set the region/environment that your Auth0 FGA store lives in. Defaults to <see cref="FgaEnvironment.US"/> if not set.
/// </summary>
/// <param name="environment">An Auth0 FGA region</param>
public Auth0FgaConnectionBuilder SetEnvironment(FgaEnvironment environment)
{
_environment = environment;
return this;
}

/// <summary>
/// Configure authentication for Auth0 FGA
/// </summary>
/// <param name="clientId">Client Id from your Auth0 FGA Account</param>
/// <param name="clientSecret">Client Secret from your Auth0 FGA Account</param>
public void WithAuthentication(string clientId, string clientSecret)
public Auth0FgaConnectionBuilder WithAuthentication(string clientId, string clientSecret)
{
ArgumentNullException.ThrowIfNull(clientId);
ArgumentNullException.ThrowIfNull(clientSecret);

_clientId = clientId;
_clientSecret = clientSecret;
return this;
}

internal FgaConnectionConfiguration Build()
Expand Down
2 changes: 1 addition & 1 deletion src/Fga.Net/Fga.Net.DependencyInjection.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

<ItemGroup>
<PackageReference Include="DotNet.ReproducibleBuilds" Version="1.1.1" PrivateAssets="All" />
<PackageReference Include="OpenFga.Sdk" Version="0.3.0" />
<PackageReference Include="OpenFga.Sdk" Version="0.3.1" />
</ItemGroup>

<ItemGroup Condition=" '$(TargetFramework)' == 'net6.0' ">
Expand Down
6 changes: 3 additions & 3 deletions tests/Fga.Net.Tests/Fga.Net.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@
<ItemGroup>
<PackageReference Include="Alba" Version="7.4.1" />
<PackageReference Include="HttpContextMoq" Version="1.5.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.9.0" />
<PackageReference Include="Ulid" Version="1.3.3" />
<PackageReference Include="xunit" Version="2.6.4" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.6">
<PackageReference Include="xunit" Version="2.7.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.7">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
Expand Down
3 changes: 2 additions & 1 deletion tests/Fga.Net.Tests/Unit/ExtensionTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,8 @@ public void AspNetCoreServiceExtensions_RegisterCorrectly(ExtensionScenario scen
new ExtensionScenario("Auth0 FGA",
config => config.ConfigureAuth0Fga(x =>
{
x.WithAuthentication(Guid.NewGuid().ToString(), Guid.NewGuid().ToString());
x.SetEnvironment(FgaEnvironment.AU)
.WithAuthentication(Guid.NewGuid().ToString(), Guid.NewGuid().ToString());
})),
new ExtensionScenario("OpenFGA - No Credentials",
config => config.ConfigureOpenFga(x =>
Expand Down

0 comments on commit d25507f

Please sign in to comment.