2

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 :)

2
  • 2
    I suspect {code}&{state} should be removed. Also read stackoverflow.com/a/41577446/34092 . Commented Jul 16, 2020 at 7:30
  • Hi, @Marrie, I already posted the code to solve your question. It works on me. If the answer solved your question, please mark it for helping more people. If not, we may be able to continue to explore solutions. Thank you for your time and efforts. Commented Jul 17, 2020 at 9:47

3 Answers 3

2

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

Sign up to request clarification or add additional context in comments.

Comments

0

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);
...

}

Comments

-1

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

Comments

Your Answer

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.