Reputation: 26091
I'm trying to implement OAuth2 with Fitbit in my WebAPI applications. I'm able to make the initial request to the fitbit api. But when it comes back the the server I'm getting a error saying that I cannot find the callback url
[HttpPost]
public async Task<HttpResponseMessage> Authorize(UserAuthRequestDTO request)
{
if (string.IsNullOrEmpty(request.PatientID) || string.IsNullOrEmpty(request.Provider))
Request.CreateResponse(HttpStatusCode.BadRequest, ErrorLookup.GetErrorMessage("invalid_input"), Configuration.Formatters.JsonFormatter);
var userId = User.Identity.GetUserId();
if (userId == null)
return Request.CreateResponse(HttpStatusCode.BadRequest, ErrorLookup.GetErrorMessage("invalid_token"), Configuration.Formatters.JsonFormatter);
var accUser = await GetUserById(userId);
_currentUser = AccountUtils.GetOrgAndUserInfo(accUser);
var callbackUrl = $"{Request.RequestUri.GetLeftPart(UriPartial.Authority)}/oauth2/callback";
IOAuthHandler handler;
switch (request.Provider)
{
case "Fitbit":
handler = new FitbitHandler(callbackUrl);
break;
case "Withings":
handler = new WithingsHandler(callbackUrl);
break;
default:
return Request.CreateResponse(HttpStatusCode.BadRequest, ErrorLookup.GetErrorMessage("invalid_input"), Configuration.Formatters.JsonFormatter);
}
var authorizationUrl = handler.RequestUserAuthorizationUrl(request.PatientID,_currentUser.Org);
return Request.CreateResponse(HttpStatusCode.OK, authorizationUrl);
}
[HttpPost]
public async Task<HttpResponseMessage> Callback(UserAuthDTO request)
{
if (string.IsNullOrEmpty(request.PatientID))
Request.CreateResponse(HttpStatusCode.BadRequest, ErrorLookup.GetErrorMessage("invalid_input"), Configuration.Formatters.JsonFormatter);
var userId = User.Identity.GetUserId();
if (userId == null)
Upvotes: 0
Views: 91
Reputation: 6698
You are setting the callback url to
...oauth2/callback?code=3aa6e9e....
But in your action, your route is
...api/oauth2/callback
You are missing "api"
in your definition
Upvotes: 1