Skip to content

Commit

Permalink
Add authentication examples (#3135)
Browse files Browse the repository at this point in the history
  • Loading branch information
apedroferreira authored Feb 14, 2024
1 parent d2a07fb commit f0b858d
Show file tree
Hide file tree
Showing 16 changed files with 154 additions and 1 deletion.
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ If your application has dependencies other than `@mui/toolpad`, you have to temp
1. Make sure to start the build in watch mode again and the run the app with
```bash
pnpm toolpad dev examples/qr-generator --dev
pnpm toolpad dev examples/qr-generator/toolpad --dev
```
### Linking Toolpad in a folder on your system (advanced)
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 7 additions & 0 deletions docs/src/modules/components/ExamplesGrid.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,13 @@ function layouts() {
href: 'https://github.com/mui/mui-toolpad/tree/master/examples/charts',
source: 'https://github.com/mui/mui-toolpad/tree/master/examples/charts',
},
{
title: 'Google Authentication',
description: 'An app that shows how to set up Google authentication in Toolpad.',
src: '/static/toolpad/marketing/auth-google.png',
href: 'https://github.com/mui/mui-toolpad/tree/master/examples/auth-google',
source: 'https://github.com/mui/mui-toolpad/tree/master/examples/auth-google',
},
{
title: 'Custom server',
description: 'An app that shows how to use Toolpad with a custom server.',
Expand Down
4 changes: 4 additions & 0 deletions examples/auth-github/.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
TOOLPAD_AUTH_SECRET=

TOOLPAD_GITHUB_CLIENT_ID=
TOOLPAD_GITHUB_CLIENT_SECRET=
35 changes: 35 additions & 0 deletions examples/auth-github/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# GitHub Authentication

<p class="description">An app that shows how to set up GitHub authentication in Toolpad.</p>

Example showcasing how to set up GitHub authentication in a Toolpad app. [The docs](https://mui.com/toolpad/concepts/authentication/).

<a target="_blank">
<img src="https://mui.com/static/toolpad/marketing/auth-github.png" alt="GitHub Authentication" style="aspect-ratio: 131/88;" width="524">
</a>

## How to run

To use this example, you need to set the environment variables shown in [.env.example](.env.example).
To get those values, please:

- Follow [this section](https://mui.com/toolpad/concepts/authentication/#authentication-secret) on how to create an authentication secret.
- Set up your own GitHub OAuth app by following [these instructions](https://mui.com/toolpad/concepts/authentication/#github).

Then, use `create-toolpad-app` to bootstrap the example:

```bash
npx create-toolpad-app@latest --example auth-github
```

```bash
yarn create toolpad-app --example auth-github
```

```bash
pnpm create toolpad-app --example auth-github
```

or:

[![Open in StackBlitz](https://developer.stackblitz.com/img/open_in_stackblitz.svg)](https://stackblitz.com/fork/github/mui/mui-toolpad/tree/master/examples/auth-github)
13 changes: 13 additions & 0 deletions examples/auth-github/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"name": "auth-github",
"version": "0.1.0",
"private": true,
"scripts": {
"dev": "toolpad dev",
"build": "toolpad build",
"start": "toolpad start"
},
"dependencies": {
"@mui/toolpad": "0.1.49"
}
}
1 change: 1 addition & 0 deletions examples/auth-github/toolpad/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.generated
6 changes: 6 additions & 0 deletions examples/auth-github/toolpad/application.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
apiVersion: v1
kind: application
spec:
authentication:
providers:
- provider: github
14 changes: 14 additions & 0 deletions examples/auth-github/toolpad/pages/protectedpage/page.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# yaml-language-server: $schema=https://raw.githubusercontent.com/mui/mui-toolpad/v0.1.49/docs/schemas/v1/definitions.json#properties/Page

apiVersion: v1
kind: page
spec:
alias:
- sP_2TKM
title: Protected Page
displayName: Protected Page
content:
- component: Text
name: text
props:
value: Only authenticated users can see me.
4 changes: 4 additions & 0 deletions examples/auth-google/.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
TOOLPAD_AUTH_SECRET=

TOOLPAD_GOOGLE_CLIENT_ID=
TOOLPAD_GOOGLE_CLIENT_SECRET=
35 changes: 35 additions & 0 deletions examples/auth-google/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Google Authentication

<p class="description">An app that shows how to set up Google authentication in Toolpad.</p>

Example showcasing how to set up Google authentication in a Toolpad app. [The docs](https://mui.com/toolpad/concepts/authentication/).

<a target="_blank">
<img src="https://mui.com/static/toolpad/marketing/auth-google.png" alt="Google Authentication" style="aspect-ratio: 131/88;" width="524">
</a>

## How to run

To use this example, you need to set the environment variables shown in [.env.example](.env.example).
To get those values, please:

- Follow [this section](https://mui.com/toolpad/concepts/authentication/#authentication-secret) on how to create an authentication secret.
- Set up your own Google OAuth client ID by following [these instructions](https://mui.com/toolpad/concepts/authentication/#google).

Then, use `create-toolpad-app` to bootstrap the example:

```bash
npx create-toolpad-app@latest --example auth-google
```

```bash
yarn create toolpad-app --example auth-google
```

```bash
pnpm create toolpad-app --example auth-google
```

or:

[![Open in StackBlitz](https://developer.stackblitz.com/img/open_in_stackblitz.svg)](https://stackblitz.com/fork/github/mui/mui-toolpad/tree/master/examples/auth-google)
13 changes: 13 additions & 0 deletions examples/auth-google/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"name": "auth-google",
"version": "0.1.0",
"private": true,
"scripts": {
"dev": "toolpad dev",
"build": "toolpad build",
"start": "toolpad start"
},
"dependencies": {
"@mui/toolpad": "0.1.49"
}
}
1 change: 1 addition & 0 deletions examples/auth-google/toolpad/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.generated
6 changes: 6 additions & 0 deletions examples/auth-google/toolpad/application.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
apiVersion: v1
kind: application
spec:
authentication:
providers:
- provider: google
14 changes: 14 additions & 0 deletions examples/auth-google/toolpad/pages/protectedpage/page.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# yaml-language-server: $schema=https://raw.githubusercontent.com/mui/mui-toolpad/v0.1.49/docs/schemas/v1/definitions.json#properties/Page

apiVersion: v1
kind: page
spec:
alias:
- sP_2TKM
title: Protected Page
displayName: Protected Page
content:
- component: Text
name: text
props:
value: Only authenticated users can see me.

0 comments on commit f0b858d

Please sign in to comment.