Marrie
Marrie

Reputation: 31

Routing a redirect URL in Web Api .Net

I am working on Github api Oauth. The main problem is to match callback URl with method in Web Api

     [HttpGet]
    [Route("api/values/callback/{code}&{state}")]
    public JsonResult Get (string code, string state)
    {
        var s = User.Claims;
        return new JsonResult(s);
    }

In StartUp file: options.CallbackPath = new PathString("/api/values/callback/"); Redirect in URL that should match an action in service http://localhost:5000/api/values/callback/?code=b1b0659f6e0&state=CfDJ8Ir-xT So, I can not build rout which has pattern /?param1&param2 Here is redirect URL that should match :

Would be glad for help :)

Upvotes: 2

Views: 724

Answers (3)

B.Ramburn
B.Ramburn

Reputation: 306

If you're using OidClient you can use the following to inject the service to the method and get the querystring to process.


// route method here
public async Task<ActionResult> ProcessCallback([FromServices] HttpListenerRequest request){
...

// generate the options using `OidcClientOptions`
 var client = new OidcClient(options);
        var result = await client.ProcessResponseAsync(request.QueryString.ToString(), null);
...

}

Upvotes: 0

Michael Wang
Michael Wang

Reputation: 4022

You can use [FromQuery] to get values from the query string.

    [HttpGet] 
    [Route("api/values/callback")]
    public JsonResult Get([FromQuery]string code, string state)
    {
        string s = "code:" + code + "         state:" + state;
        return new JsonResult(s);
    }

Test

enter image description here

Upvotes: 2

StefanaB
StefanaB

Reputation: 183

I would suggest to edit the route to api/values/callback/code={code}&state={state} .

Upvotes: -1

Related Questions