-
-
Notifications
You must be signed in to change notification settings - Fork 748
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: mapping no default policy and policy not found responses
- Loading branch information
Showing
11 changed files
with
113 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
src/HotChocolate/AspNetCore/src/AspNetCore.Authorization.Opa/OpaResultFieldConverter.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
using System.Text.Json; | ||
using System.Text.Json.Serialization; | ||
|
||
namespace HotChocolate.AspNetCore.Authorization.Opa; | ||
|
||
/// <summary> | ||
/// Opa Result Converter | ||
/// </summary> | ||
/// <remarks> | ||
/// As described in https://www.openpolicyagent.org/docs/latest/rest-api/#get-a-document | ||
/// The server returns 200 if the path refers to an undefined document. | ||
/// In this case, the response will not contain a result property. | ||
/// The property is actually returned as an empty object '{ }'. | ||
/// Therefore, it can't be deserialized as nullable boolean by default, hence this converter. | ||
/// </remarks> | ||
public class OpaResultFieldConverter : JsonConverter<bool?> | ||
{ | ||
public override bool? Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) | ||
{ | ||
if (reader.TokenType != JsonTokenType.StartObject) return reader.GetBoolean(); | ||
reader.Skip(); | ||
return null; | ||
} | ||
|
||
public override void Write(Utf8JsonWriter writer, bool? value, JsonSerializerOptions options) | ||
{ | ||
if (value is { } v) writer.WriteBooleanValue(v); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 5 additions & 1 deletion
6
src/HotChocolate/AspNetCore/src/AspNetCore.Authorization.Opa/Types/QueryResponse.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
...hocolate/AspNetCore/test/AspNetCore.Authorization.Opa.Tests/Policies/has_age_defined.rego
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package graphql.authz.has_age_defined | ||
|
||
import input.request | ||
|
||
default allow = false | ||
|
||
input["token"] = replace(request.headers["Authorization"], "Bearer ", "") | ||
|
||
claims := io.jwt.decode(input.token)[1] | ||
|
||
allow { | ||
claims.birthdate | ||
} |