Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add authentication examples #3135

Merged
merged 17 commits into from
Feb 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Copy link
Member Author

@apedroferreira apedroferreira Feb 13, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I don't include /toolpad it creates the files outside the toolpad folder, that's not expected, right? Or am I doing something wrong?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did this get resolved?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It works well after this change and it matches the command that was already in step 3 above it, so I'm pretty sure this should be the way to write it.

```

### 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',
mbrookes marked this conversation as resolved.
Show resolved Hide resolved
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.
Loading