2

Is there a clear and simple way to use OAuth login providers in a ReactJS and Asp.Net Core Web API project? I am looking for a solution without Identity and Razor pages. Only ReactJS and Asp.Net Core Web API. And do we need the oidc-client library for this?

2

1 Answer 1

1

In case you are referring to OpenID Connect:

React app

The react app probably wants to initiate the authentication, get hold of the access token which needs to be included in requests to the API, as well as refresh the access token once it is expired. You don't strictly need a library for that, but it makes your life easier, especially if you use one specific to react, like React OIDC, which is a wrapper for the oidc-client.

An example for including the token in API requests when using axios-hooks can be found in the Authentication and token refresh example. See bearer token for further information.

Web API

To handle the access token provide by the react app, you can add make use of the JWT bearer authentication middleware. Guides for integrating the middleware can be found in Protecting an API using Client Credentials or this question.

For more details you could have a look at the ASP.NET Core - Authentication & Authorization Tutorial.

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

2 Comments

Thanks for the answer, but I am looking for a solution that includes WebAPI, No Razor Pages, No MVC, Pure web api. And External Authentication like google authentication with a simple ReactJS app. And I like to know its necessary to use oidc-client or it can be done with simple fetch requests.
@RashidMousavyKhoshrou were you able to find what you wanted if so please let me know. I am still looking for something like this

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.