JWT Bearer Authentication Load to API fails

Anonymous
2023-09-27T05:57:10.0133333+00:00

I created API with JWT Token , I know I need to pass credentials but just for

test purposes I used get method instead of post.

https://github.com/KalyanAllam/VisitsApi

Where Auth Controller generates the token.

https://github.com/KalyanAllam/VisitsApi/blob/master/VisitsApi/Controllers/AuthController.cs

https://visitsapi.azurewebsites.net/api/Auth

when token is passed to Visits Controller It displays JSON info

I tested the same in below code , when I load the api with bearer the call is successful 200 code

https://github.com/KalyanAllam/JWTApiCall

But when I am calling api https://visitsapi.azurewebsites.net/ from https://github.com/KalyanAllam/PatientPortal/blob/master/PatientPortal/Controllers/VisitsNewController.cs

it is not returning any value.

Due to some reason I am not able to debug the code.

Please suggest

Capturebearer.JPG

ASP.NET Core
ASP.NET Core
A set of technologies in the .NET Framework for building web applications and XML web services.
4,506 questions
0 comments No comments
{count} votes

Accepted answer
  1. Zeeshan Nasir Bajwa 646 Reputation points Student Ambassador
    2023-09-27T06:11:27.94+00:00

    Hi @Anonymous ,

    It seems like you are encountering an issue with making API calls to VisitsApi from your PatientPortal application. Debugging remote issues can be challenging, but I can provide some general steps and suggestions to help you troubleshoot the problem:

    Check Endpoint URLs: Ensure that the URLs you are using to make API calls are correct and match the endpoints in your VisitsApi. In your VisitsNewController.cs file, double-check the URL you are using for the API call.

    Check CORS Configuration: If your API and your client application are hosted on different domains, you may need to configure Cross-Origin Resource Sharing (CORS) on your API server to allow requests from the domain where your client application is hosted. Make sure CORS is correctly configured in your VisitsApi.

    Authentication Token: Verify that the JWT token you are passing in the request header is correctly generated and formatted. It should have the "Bearer" prefix followed by the actual token.

    Authentication and Authorization: Ensure that your VisitsApi is correctly authenticating and authorizing requests. Check if the token passed in the request header is being validated properly.

    Logging and Error Handling: Implement proper logging and error handling in your API. This will help you capture any errors that might be occurring on the server side. Check your server logs for any error messages.

    Network Issues: Make sure there are no network-related issues preventing the API call. You can try making the API call from a tool like Postman or curl to see if it works outside of your application. This will help determine if the issue is with your API or your client application.

    HTTP Response Codes: Check the HTTP response codes returned by the API. A 200 response code indicates success, while other codes like 401 (Unauthorized) or 403 (Forbidden) indicate authentication or authorization issues.

    Debugging Tools: If you are having difficulty debugging, consider using tools like Fiddler or browser developer tools to inspect the network requests and responses. This can help you identify any issues with the API call.

    Deployment Issues: Ensure that both your VisitsApi and PatientPortal applications are deployed correctly and are accessible from their respective URLs. Verify that there are no firewall or security settings blocking the requests.

    Testing in Staging Environment: If possible, set up a staging or test environment where you can replicate the issue in a controlled environment. This will allow you to debug without affecting the production systems.

    If you provide more specific information about any error messages or behaviors you are encountering, I can offer more targeted guidance. Additionally, if you have access to server logs or any error messages, sharing them here would be helpful for further diagnosis.

    0 comments No comments

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.