|
| 1 | +--- |
| 2 | +title: Magic Authentication |
| 3 | +order: 5 |
| 4 | +--- |
| 5 | + |
| 6 | +# Sharing sites with magic authentication |
| 7 | + |
| 8 | +Expose allows you to protect your shared sites with a simple email-based authentication flow called "magic authentication". Instead of a browser popup asking for credentials, visitors see a clean login form where they enter their email address. Once submitted, a secure cookie is set allowing access on subsequent requests. |
| 9 | + |
| 10 | +This provides a more user-friendly authentication experience compared to basic authentication, while still providing security for your shared sites. |
| 11 | + |
| 12 | +## Using magic authentication |
| 13 | + |
| 14 | +To share your site with magic authentication that accepts any email address, use the `--magic-auth` flag: |
| 15 | + |
| 16 | +```bash |
| 17 | +expose share my-site.test --magic-auth |
| 18 | +``` |
| 19 | + |
| 20 | +When someone visits your shared URL, they'll see a login form asking for their email address. After entering a valid email, they'll be redirected to the original page and can browse freely for the next 7 days. |
| 21 | + |
| 22 | +## Restricting access by email domain |
| 23 | + |
| 24 | +You can restrict access to specific email domains using the `@domain.com` pattern: |
| 25 | + |
| 26 | +```bash |
| 27 | +# Only allow emails from @company.com |
| 28 | +expose share my-site.test --magic-auth=@company.com |
| 29 | +``` |
| 30 | + |
| 31 | +This is useful when sharing development sites with your team - only team members with company email addresses can access the site. |
| 32 | + |
| 33 | +## Restricting access to multiple domains |
| 34 | + |
| 35 | +Separate multiple patterns with commas: |
| 36 | + |
| 37 | +```bash |
| 38 | +# Allow emails from @company.com and @partner.com |
| 39 | +expose share my-site.test --magic-auth=@company.com,@partner.com |
| 40 | +``` |
| 41 | + |
| 42 | +## Allowing specific email addresses |
| 43 | + |
| 44 | +You can also allow specific email addresses: |
| 45 | + |
| 46 | +```bash |
| 47 | +# Only allow these specific users |
| 48 | +expose share my-site.test --magic-auth=alice@example.com,bob@example.com |
| 49 | +``` |
| 50 | + |
| 51 | +## Combining domains and specific emails |
| 52 | + |
| 53 | +Mix domain patterns and specific email addresses as needed: |
| 54 | + |
| 55 | +```bash |
| 56 | +# Allow anyone from @company.com plus a specific contractor |
| 57 | +expose share my-site.test --magic-auth=@company.com,contractor@external.com |
| 58 | +``` |
| 59 | + |
| 60 | +## How it works |
| 61 | + |
| 62 | +1. When a visitor accesses your shared URL without a valid authentication cookie, they see a login form |
| 63 | +2. They enter their email address and submit the form |
| 64 | +3. If the email matches the allowed patterns (or any email is allowed), a signed cookie is set |
| 65 | +4. The visitor is redirected to the original page they requested |
| 66 | +5. Future requests include the cookie and pass through to your local site |
| 67 | +6. The authentication cookie expires after 7 days |
| 68 | + |
| 69 | +## Connection status |
| 70 | + |
| 71 | +When magic authentication is enabled, the connection table shows the current auth configuration: |
| 72 | + |
| 73 | +``` |
| 74 | +┌────────────┬──────────────────────────────────────────────┐ |
| 75 | +│ Shared site│ my-site.test │ |
| 76 | +│ Dashboard │ http://127.0.0.1:4040 │ |
| 77 | +│ Public URL │ https://my-site.sharedwithexpose.com │ |
| 78 | +│ Magic Auth │ Enabled (@company.com) │ |
| 79 | +└────────────┴──────────────────────────────────────────────┘ |
| 80 | +``` |
| 81 | + |
| 82 | +## Combining with other options |
| 83 | + |
| 84 | +Magic authentication works with other sharing options: |
| 85 | + |
| 86 | +```bash |
| 87 | +# Custom subdomain with magic auth |
| 88 | +expose share my-site.test --subdomain=demo --magic-auth=@company.com |
| 89 | + |
| 90 | +# With custom domain |
| 91 | +expose share my-site.test --domain=mycompany.com --magic-auth |
| 92 | + |
| 93 | +# With QR code |
| 94 | +expose share my-site.test --magic-auth --qr-code |
| 95 | +``` |
| 96 | + |
| 97 | +> **Note**: Magic authentication cannot be combined with basic authentication (`--auth`). Choose one authentication method per share session. |
0 commit comments