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

feat(passkeys): register #29

Merged
merged 36 commits into from
Jul 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
d7e21a2
UI component, route, zitadel server functions
peintnermax Jun 8, 2023
717c46b
use session token for passkey register
peintnermax Jun 8, 2023
0840518
createpasskeyregistrationlink
peintnermax Jun 12, 2023
69301d7
navigator, utils
peintnermax Jun 13, 2023
73d5c6e
passkey verify, page styles
peintnermax Jun 15, 2023
fbbc48e
split up register, session for passkeys
peintnermax Jun 16, 2023
3aa8e8f
create session with password on register
peintnermax Jun 16, 2023
ed7d612
rm logs
peintnermax Jun 19, 2023
f8bbfb3
passwordless prompt page
peintnermax Jun 19, 2023
60cf166
register session with password
peintnermax Jun 19, 2023
4643e9a
Update apps/login/app/(login)/passkey/add/page.tsx
peintnermax Jun 21, 2023
6431ea0
Update apps/login/app/(login)/accounts/page.tsx
peintnermax Jun 21, 2023
9edfdc8
Update apps/login/ui/SetPasswordForm.tsx
peintnermax Jun 21, 2023
3a729bb
Update apps/login/app/session/route.ts
peintnermax Jun 21, 2023
793814c
Update apps/login/ui/RegisterFormWithoutPassword.tsx
peintnermax Jun 21, 2023
ba017d7
Update apps/login/ui/RegisterFormWithoutPassword.tsx
peintnermax Jun 21, 2023
5941ec6
Update apps/login/lib/zitadel.ts
peintnermax Jun 21, 2023
9f13fd7
Update apps/login/lib/zitadel.ts
peintnermax Jun 21, 2023
98fee5c
throw custom error when context could not be read
peintnermax Jun 21, 2023
05314c7
show user creation error
peintnermax Jun 21, 2023
ad7f9d2
rm logs
peintnermax Jun 21, 2023
3379779
user avatar fallback
peintnermax Jun 21, 2023
bd12290
remove unused register success pages
peintnermax Jun 21, 2023
4e1d8fb
remove redundant code,unused imports
peintnermax Jun 21, 2023
bf474f4
rm unused import
peintnermax Jun 21, 2023
f2ced63
rm export
peintnermax Jun 21, 2023
7cbc467
login with passkey
peintnermax Jun 22, 2023
29ac45d
Merge branch 'main' into passkey-registration
peintnermax Jun 26, 2023
f334f0f
login component
peintnermax Jun 27, 2023
6fcb1ae
fix register
peintnermax Jun 27, 2023
b5b7099
Merge branch 'passkey-login' into passkey-registration
peintnermax Jun 27, 2023
912958e
rm login part
peintnermax Jun 28, 2023
a3b412e
fix configuring acceptance env
eliobischof Jun 28, 2023
0f2968e
cleanup
peintnermax Jun 29, 2023
00c8b64
spread
peintnermax Jun 29, 2023
5e93ed7
empty avatar without loginname
peintnermax Jun 29, 2023
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 @@ -51,7 +51,7 @@ docker compose --file ./acceptance/docker-compose.yaml pull
docker compose --file ./acceptance/docker-compose.yaml run setup

# Configure your shell to use the environment variables written to ./apps/login/.env.acceptance
source ./apps/login/.env.acceptance
export $(cat ./apps/login/.env.acceptance | xargs)
```

### Developing Against Your ZITADEL Cloud Instance
Expand Down
39 changes: 22 additions & 17 deletions acceptance/docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -1,49 +1,54 @@
version: '3.8'
version: "3.8"

services:
zitadel:
user: '${ZITADEL_DEV_UID}'
image: '${ZITADEL_IMAGE:-ghcr.io/zitadel/zitadel:latest}'
user: "${ZITADEL_DEV_UID}"
image: "${ZITADEL_IMAGE:-ghcr.io/zitadel/zitadel:latest}"
command: 'start-from-init --masterkey "MasterkeyNeedsToHave32Characters" --tlsMode disabled --config /zitadel.yaml --steps /zitadel.yaml'
ports:
- "8080:8080"
- "8080:8080"
volumes:
- ./machinekey:/machinekey
- ./zitadel.yaml:/zitadel.yaml
depends_on:
db:
condition: 'service_healthy'
condition: "service_healthy"

db:
image: 'cockroachdb/cockroach:v22.2.2'
command: 'start-single-node --insecure --http-addr :9090'
image: "cockroachdb/cockroach:v22.2.2"
command: "start-single-node --insecure --http-addr :9090"
healthcheck:
test: ['CMD', 'curl', '-f', 'http://localhost:9090/health?ready=1']
interval: '10s'
timeout: '30s'
test: ["CMD", "curl", "-f", "http://localhost:9090/health?ready=1"]
interval: "10s"
timeout: "30s"
retries: 5
start_period: '20s'
start_period: "20s"
ports:
- "26257:26257"
- "9090:9090"

wait_for_zitadel:
image: curlimages/curl:8.00.1
command: [ "/bin/sh", "-c", "i=0; while ! curl http://zitadel:8080/debug/ready && [ $$i -lt 30 ]; do sleep 1; i=$$((i+1)); done; [ $$i -eq 30 ] && exit 1 || exit 0" ]
command:
[
"/bin/sh",
"-c",
"i=0; while ! curl http://zitadel:8080/debug/ready && [ $$i -lt 30 ]; do sleep 1; i=$$((i+1)); done; [ $$i -eq 30 ] && exit 1 || exit 0",
]
depends_on:
- zitadel

setup:
user: '${ZITADEL_DEV_UID}'
user: "${ZITADEL_DEV_UID}"
container_name: setup
build: .
environment:
KEY: /key/zitadel-admin-sa.json
SERVICE: http://zitadel:8080
WRITE_ENVIRONMENT_FILE: /apps/login/.env.local
WRITE_ENVIRONMENT_FILE: /apps/login/.env.acceptance
volumes:
- "./machinekey:/key"
- "../apps/login:/apps/login"
- "./machinekey:/key"
- "../apps/login:/apps/login"
depends_on:
wait_for_zitadel:
condition: 'service_completed_successfully'
condition: "service_completed_successfully"
1 change: 0 additions & 1 deletion apps/login/app/(login)/accounts/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ async function loadSessions(): Promise<Session[]> {

export default async function Page() {
let sessions = await loadSessions();

return (
<div className="flex flex-col items-center space-y-4">
<h1>Accounts</h1>
Expand Down
2 changes: 1 addition & 1 deletion apps/login/app/(login)/error.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export default function Error({ error, reset }: any) {
}, [error]);

return (
<Boundary labels={["Home page Error UI"]} color="red">
<Boundary labels={["Login Error"]} color="red">
<div className="space-y-4">
<div className="text-sm text-red-500 dark:text-red-500">
<strong className="font-bold">Error:</strong> {error?.message}
Expand Down
72 changes: 72 additions & 0 deletions apps/login/app/(login)/passkey/add/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
import { getSession, server } from "#/lib/zitadel";
import Alert, { AlertType } from "#/ui/Alert";
import RegisterPasskey from "#/ui/RegisterPasskey";
import UserAvatar from "#/ui/UserAvatar";
import { getMostRecentCookieWithLoginname } from "#/utils/cookies";

export default async function Page({
searchParams,
}: {
searchParams: Record<string | number | symbol, string | undefined>;
}) {
const { loginName, prompt } = searchParams;

const sessionFactors = await loadSession(loginName);

async function loadSession(loginName?: string) {
const recent = await getMostRecentCookieWithLoginname(loginName);
return getSession(server, recent.id, recent.token).then((response) => {
if (response?.session) {
return response.session;
}
});
}
const title = !!prompt
? "Authenticate with a passkey"
: "Use your passkey to confirm it's really you";
const description = !!prompt
? "When set up, you will be able to authenticate without a password."
: "Your device will ask for your fingerprint, face, or screen lock";

return (
<div className="flex flex-col items-center space-y-4">
<h1>{title}</h1>

{sessionFactors && (
<UserAvatar
loginName={loginName ?? sessionFactors.factors?.user?.loginName}
displayName={sessionFactors.factors?.user?.displayName}
showDropdown
></UserAvatar>
)}
<p className="ztdl-p mb-6 block">{description}</p>

<Alert type={AlertType.INFO}>
<span>
A passkey is an authentication method on a device like your
fingerprint, Apple FaceID or similar.
<a
className="text-primary-light-500 dark:text-primary-dark-500 hover:text-primary-light-300 hover:dark:text-primary-dark-300"
target="_blank"
href="https://zitadel.com/docs/guides/manage/user/reg-create-user#with-passwordless"
>
Passwordless Authentication
</a>
</span>
</Alert>

{!sessionFactors && (
<div className="py-4">
<Alert>
Could not get the context of the user. Make sure to enter the
username first or provide a loginName as searchParam.
</Alert>
</div>
)}

{sessionFactors?.id && (
<RegisterPasskey sessionId={sessionFactors.id} isPrompt={!!prompt} />
)}
</div>
);
}
46 changes: 46 additions & 0 deletions apps/login/app/(login)/passkey/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import { getSession, server } from "#/lib/zitadel";
import Alert from "#/ui/Alert";
import UserAvatar from "#/ui/UserAvatar";
import { getMostRecentCookieWithLoginname } from "#/utils/cookies";

export default async function Page({
searchParams,
}: {
searchParams: Record<string | number | symbol, string | undefined>;
}) {
const { loginName } = searchParams;
const sessionFactors = await loadSession(loginName);

async function loadSession(loginName?: string) {
const recent = await getMostRecentCookieWithLoginname(loginName);

return getSession(server, recent.id, recent.token).then((response) => {
if (response?.session) {
return response.session;
}
});
}

return (
<div className="flex flex-col items-center space-y-4">
<h1>Login with Passkey</h1>
<p className="ztdl-p mb-6 block">Authenticate with your passkey device</p>
{!sessionFactors && (
<div className="py-4">
<Alert>
Could not get the context of the user. Make sure to enter the
username first or provide a loginName as searchParam.
</Alert>
</div>
)}

{sessionFactors && (
<UserAvatar
loginName={loginName ?? sessionFactors.factors?.user?.loginName}
displayName={sessionFactors.factors?.user?.displayName}
showDropdown
></UserAvatar>
)}
</div>
);
}
35 changes: 0 additions & 35 deletions apps/login/app/(login)/password/change/page.tsx

This file was deleted.

2 changes: 1 addition & 1 deletion apps/login/app/(login)/password/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export default async function Page({

{sessionFactors && (
<UserAvatar
loginName={loginName ?? sessionFactors.factors?.user?.loginName ?? ""}
loginName={loginName ?? sessionFactors.factors?.user?.loginName}
displayName={sessionFactors.factors?.user?.displayName}
showDropdown
></UserAvatar>
Expand Down
133 changes: 0 additions & 133 deletions apps/login/app/(login)/password/set/page.tsx

This file was deleted.

Loading