diff --git a/examples/react-spa/README.md b/examples/react-spa/README.md index 8018b6c..9e86321 100644 --- a/examples/react-spa/README.md +++ b/examples/react-spa/README.md @@ -4,6 +4,15 @@ This project demonstrates how to implement the Authorization Code Flow with PKCE Disclaimer: This project is for educational purposes only and should not be used in production without proper security review and testing. +## Deployment + +This project is deployed the following platforms: + +- [Cloudflare Pages](https://react-spa-authorization-code-flow.pages.dev/) +- [Vercel](https://react-spa-authorization-code-flow.vercel.app/) +- [Netlify](https://react-spa-authorization-code-flow.netlify.app/) +- [Firebase Hosting](https://react-spa-authorization-code-flow.web.app/) + ## Prerequisites Before getting started, make sure you have the following: @@ -23,11 +32,13 @@ Before getting started, make sure you have the following: ```bash cd openid-connect-examples/react-spa-authorization-code-flow - npm install + npm ci ``` 3. Configure the OpenID Connect provider: +If you don't have an OpenID Connect provider, you can use [TestID OpenID Connect Provider](https://testid.cerberauth.com/). + - Obtain the client ID and client secret from your OpenID Connect provider. - Register the redirect URI for your React SPA in the provider's developer console. @@ -59,6 +70,7 @@ Before getting started, make sure you have the following: ## Additional Resources +- [oauth4webapi](https://github.com/panva/oauth4webapi) - [OpenID Connect](https://openid.net/) - [OAuth 2.0 Authorization Code Flow](https://oauth.net/2/grant-types/authorization-code/) - [PKCE](https://oauth.net/2/pkce/) diff --git a/examples/react-spa/src/App.tsx b/examples/react-spa/src/App.tsx index 0761d57..b5cd2c2 100644 --- a/examples/react-spa/src/App.tsx +++ b/examples/react-spa/src/App.tsx @@ -1,7 +1,6 @@ import { Router } from 'wouter' import { AuthProvider } from './lib/auth/AuthProvider' -import { Header } from './components/Header' import { PageRouter } from './components/PageRouter' function App() { @@ -11,13 +10,7 @@ function App() { clientId={import.meta.env.VITE_OIDC_CLIENT_ID} > -
-
-
- - -
-
+
) diff --git a/examples/react-spa/src/components/Button.tsx b/examples/react-spa/src/components/Button.tsx new file mode 100644 index 0000000..4a2521c --- /dev/null +++ b/examples/react-spa/src/components/Button.tsx @@ -0,0 +1,14 @@ +export interface ButtonProps extends React.ButtonHTMLAttributes { + children: React.ReactNode +} + +export const Button: React.FC = ({ children, ...props }) => { + return ( + + ) +} diff --git a/examples/react-spa/src/components/Header.tsx b/examples/react-spa/src/components/Header.tsx deleted file mode 100644 index 22936eb..0000000 --- a/examples/react-spa/src/components/Header.tsx +++ /dev/null @@ -1,33 +0,0 @@ -import React from 'react' -import { useAuth } from '../lib/auth/useAuth' - -export const Header: React.FC = () => { - const { isAuthenticated, login, logout, user } = useAuth() - - return ( -
-
-

My App

-
-
- {isAuthenticated ? ( - <> - {user?.picture && ( - Profile - )} - - - ) : ( - <> - - {/* */} - - )} -
-
- ); -}; diff --git a/examples/react-spa/src/pages/home.tsx b/examples/react-spa/src/pages/home.tsx index 93fa80b..78aeeab 100644 --- a/examples/react-spa/src/pages/home.tsx +++ b/examples/react-spa/src/pages/home.tsx @@ -1,7 +1,37 @@ +import { Button } from '../components/Button' +import { useAuth } from '../lib/auth/useAuth' + export function Home() { + const { login, logout, isAuthenticated } = useAuth() + return ( -
-

Welcome to the home page

+
+
+

+ React SPA Example using OpenID Connect +

+

+ This example demonstrates how to authenticate users in a React Single Page Application (SPA) using OpenID Connect Protocol. +

+ {isAuthenticated ? ( + + ) : ( + + )} +

+ If you want to checkout out how to implement OpenID Connect in your React SPA, take a look at the source code. +

+
+ +
) }