Static website
In this tutorial, we will create a simple page with a “Sign in” button. Once clicked, the user will be redirected to passwordless.ID to authenticate and return back to this page and show the user profile.
Steps:
- redirect to the Passwordless.ID authorization endpoint
- the user signs in/up
- the user gives your domain permission to access its profile
- Passwordless.ID redirects back to your website with an
id_token
- this
id_token
is a signed Json Web Token containing the profile - parse and verify the
id_token
to show the user profile
The authorization step
Invoke https://passwordless.id/api/openid/authorize?client_id=
The redirect_uri
is the URL the user gets redirected to once authenticated.
For security reasons, it must belong to the same domain as your client_id
.
A simple way to generate such a link is as follows:
Of course, redirect_uri
can also be a fixed URL, like a welcome page or a dashboard.
Back to the page
Once the user is authenticated and returned to the provided redirect_uri
, an id_token
parameter will be added to the hash.
It looks like:
This id_token
Create an HTML page
Trigger the sign-in
It uses the OAuth2 / OpenID flow using the @passwordless-id/connect library.
The code for that looks as follows.
Show the profile
The retrieved user
has the following structure.
Trigger the sign-out
Using the token for API calls
Once you obtain the user, you can also send the token_id
to your server API as proof of the user’s authenticity. This is a Json Web Token containing a signature that can be verified by common libraries.