2

I need a little guidance. I am trying to implement oAuth2 authentication in my React JS application. Backend is in service now. In react on login button click, service now popup will open to authenticate user and will provide access token at redirect uri.

I am having client id, client secret, access token uri, authorization uri, redirect uri.

But couldn't find any specific library for react js that gives oauth2 implementation. Please give me pointers so I can use any existing/implement oauth2 authentication for my Login page(using react).

I was trying to use ClientOAuth2, but I am not sure if this is correct to use with react js. Also, I am getting CORS error on using this library on my localhost.

Please share how to implement it properly.

Dilpreet Kaur
  • 77
  • 3
  • 10

2 Answers2

4

I have a couple of tutorials you may find useful, which use the oidc-client library.

The design patterns used are technology neutral and can be implemented in any JavaScript tech stack.

TUTORIAL 1 : PLAIN TYPESCRIPT

This focuses on the basics of Authorization Code Flow (PKCE) and a productive developer setup:

FINAL TUTORIAL: REACTJS

This focuses on some more advanced aspects, and includes an update to ReactJS:

Gary Archer
  • 22,534
  • 2
  • 12
  • 24
0

I have used react-oauth2-auth-code-flow npm package to implement AUth2 flow in my react js application. The npm package has samples to help your implementation. Check this https://www.npmjs.com/package/react-oauth2-auth-code-flow

ZedTuX
  • 2,859
  • 3
  • 28
  • 58
Santosh Karanam
  • 1,077
  • 11
  • 23