Sanyam
Sanyam

Reputation: 89

OAuth library for ReactJs

I am working on ReactJS SPA. I am trying to find the library which I can use for OAuth2 from my React SPA to get the authorization code. I tried using auth0 libraries but auth0 libraries redirect to /authorize endpoint only and there is no way to configure it. Our company's authentication server's authorization endpoint is /as/authorization. Can someone please help which React library can be used?

Upvotes: 0

Views: 6962

Answers (4)

Gary Archer
Gary Archer

Reputation: 29301

The most mainstream and mature library is oidc-client. Here are a couple of code samples of mine that use it:

The GitHub repos link to some blog posts that might be useful also.

Upvotes: 2

Sanyam
Sanyam

Reputation: 89

We ended up using hello.js in our app.

We had to customize it but it worked.

Upvotes: 0

Frenchcooc
Frenchcooc

Reputation: 1080

This is something that can be easily done with Pizzly, an open-source OAuth Integrations manager.

Here's an example of how to use Pizzly to retrieve an accessToken:

const App = () => {

  // Initialize Pizzly
  const pizzly = new Pizzly({ host: PIZZLY_HOSTNAME, publishableKey: PIZZLY_PUBLISHABLE_KEY })

  // Use the GitHub API
  const github = pizzly.integration('github')

  // The connect method lets us authenticate a user
  // to our GitHub OAuth application
  const connect = () => {
    github
      .connect()
      .then(({ authId, payload }) => {
        console.log(authId, payload.accessToken)
      })
      .catch(console.error)
  }

  // ...
};

export default App;

I've recently written a tutorial on how to use Pizzly + React.

Upvotes: 4

Ralph
Ralph

Reputation: 309

You can try using Pathfix, we have a login extension that connects to multiple providers.

Can you elaborate your OAuth use case. I am assuming since you mentioned Auth0 you are trying to use it as a login provider?

Disclaimer: I work with them

Upvotes: 0

Related Questions