1

I am working with Microsoft's Verifiable Credentials sample: https://github.com/Azure-Samples/active-directory-verifiable-credentials-dotnet/tree/main/1-asp-net-core-api-idtokenhint

Rather than use fixed contact values as per the test (see IssuerController.cs), I want to use query params from a form I have added to the Index page (e.g. an input called "firstname"). I can see the params in the results page URL, however I cannot find a way to set these correctly.

I've tried a few methods in IssuerController.cs. First by amending the static value to a query request:

payload["issuance"]["claims"]["given_name"] = HttpContext.Request.Query["firstname"].ToString();

I've also tried setting a property:

[FromQuery(Name = "firstname")]
public string firstname { get; set; }

And then adding the property to the payload:

payload["issuance"]["claims"]["given_name"] = firstname;

Sadly all of this results in the same error:

"Missing provided claims in issuance: [given_name]","target":"issuance.claims"

For reference, the method signature is

public async Task<ActionResult> IssuanceRequest()

As you may gather, I am not savvy with .NET.

What is the correct way to do this please? Thanks

phuzi
  • 12,078
  • 3
  • 26
  • 50
tomu
  • 11
  • 2
  • If you are trying to bind a query string value to a public property in a PageModel class (a Razor Pages "code behind"), you should decorate it with the `BindProperty` attribute with `SupportsGet` set to `true`: `[BindProperty(SupportsGet=true)] public string firstname { get; set; }` – Mike Brind Aug 03 '22 at 15:57
  • Thanks for the reply. No change so far though. – tomu Aug 03 '22 at 16:17
  • Try `public async Task IssuanceRequest([FromQuery] string firstname)`. – Dimitris Maragkos Aug 03 '22 at 22:29
  • No dice. Should I still be calling it using `payload["issuance"]["claims"]["given_name"] = firstname;` ? – tomu Aug 04 '22 at 07:35
  • Can you post the code of the form you are using? Is the controller action executed? Does the firstname parameter have the value entered from the form? – Dimitris Maragkos Aug 06 '22 at 11:59
  • Thanks, Dimitris. I'll add it after this comment as it's too long, but even a very basic form gives the same issues (btw - currently other variables are hard coded into IssuerController.cs). In any case, I can see the query param just fine in the URL bar, and I can print the value on screen using `Thanks, @HttpContext.Request.Query["firstname"].ToString()` so I don't think the form is the issue. – tomu Aug 08 '22 at 07:55
  • `
    `
    – tomu Aug 08 '22 at 07:57
  • I've also now tried reverting to the original sample, in case the various changes had had another impact, and just adding a very simple form to it. I've tried all the suggested methods above the result is still the same frustratingly. Thanks! – tomu Aug 08 '22 at 08:35

2 Answers2

0

Right, I'm sure there are other ways to do this but we got it working in the end by amending the IssuanceRequest method in Issuer.cshtml

fetch('/api/issuer/issuance-request?firstName=@HttpContext.Request.Query["firstName"].ToString()&lastName=@HttpContext.Request.Query["lastName"].ToString()&email=@HttpContext.Request.Query["email"].ToString()&phone=@HttpContext.Request.Query["phone"].ToString()')

Thanks for the help anyway

tomu
  • 11
  • 2
0

If I understand correctly, you just can add a parameter to you action method like this:

public async Task<ActionResult> IssuanceRequest(string firstname)

Or add a FromQuery attribute if you want to specify a source of a value, and name of query parameter (optional):

public async Task<ActionResult> IssuanceRequest([FromQuery(Name = "firstname"]string firstname)