0

To better context see Rich Authorization Requests for OAuth2

As u can read here there are some common data field types like actions, locations etc.

So I have created C# entity for EF as below:

public class AuthorizationDetails
{
 public int Id { get; set; }
 public string Type { get; set; }
 public bool AlwaysRequireConsent { get; set; }
 public ICollection<ApiResource> Locations { get; set; }
 public string SpaceDelimitedActions { get; set; }
 public string SpaceDelimitedDataTypes { get; set; }
 public string SpaceDelimitedPrivileges { get; set; }
 public ICollection<AuthorizationDetailsCustomDataField> CustomDataFields { get; set; }
 public string DisplayName { get; set; }
 public string Description { get; set; }
 public ICollection<Client> Clients { get; set; }
}

There is no problem with these common fields. But I have to handle custom JSON data fields and register them. So I have created class called AuthorizationDetailsCustomDataField which is related with one-to-many with AuthorizationDetails entity.

It looks as below:

public class AuthorizationDetailsCustomDataField
{
 public int Id { get; set; }
 public string Name { get; set; }
 public bool Required { get; set; }
}

So in JSON, the custom field with Name="custom_field" can looks like it:

{
 "custom_field":[
 "read",
 "write"
 ]
}

But it also can looks like it:

{
 "custom_field":{
 "x":1024,
 "y":2048,
 "z":{
 "a":"3096",
 "b":[
 "abc",
 "xyz"
 ]
 }
 }
}

How it looks depends on configuration. But how can I allow any configuration that developer wants? How can I design the database to make possible for developer to specify their own allowed JSON structures?

asked Feb 22, 2023 at 19:14
8
  • Did you consider saving JSON in a varchar column? This can be a good first step to get it to work... Commented Feb 22, 2023 at 19:56
  • If you choose to deploy on top of Postgres you will find it has excellent support for storing deeply nested JSON columns. Commented Feb 22, 2023 at 20:57
  • It's hard to explain what I mean. I don't want to store JSON objects but to store: what some JSON object can contains, what fields and what these fields are: arrays, strings or numbers and what the fields in fields are and so on through with depth of JSON object. Commented Feb 22, 2023 at 21:22
  • 2
    @Szyszka947: "I don't want to store JSON objects" - but why not? Would be the most simple solution for your issue. Commented Feb 22, 2023 at 21:46
  • 1
    Do you want to store an arbitrary structure in the DB, but not actual values? Try storing a JSON object with the same structure as keys, and types as values. E.g. {"customField":["string"]} or {"customField":{"x":"int","y":"int","z":{"a":"string", "b":["string"]} Commented Feb 22, 2023 at 22:18

0

Know someone who can answer? Share a link to this question via email, Twitter, or Facebook.

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.