Sign Users In
You sign your customers in to the Asset app with magic links. Your backend asks Asset for a link, then sends the customer to it. This guide shows how to create the link, where it can take your customer, and what happens when a session ends.
Before you start, the customer's Business must exist and be active. See Managing Businesses.
How signing in works
In the usual flow, your customer signs in to your platform first. When they click the button to open accounting, your platform asks Asset for a magic link and sends them to it.
Create a magic link
Call the Generate a Magic Link endpoint from your backend. The request needs an access token with the auth:create scope. See Authentication.
curl --request POST \
--url https://api.sandbox.getasset.com/v0/auth/magic-link \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '{
"business_id": "biz_123456",
"email": "jack@example.com",
"path": "/reports/statements"
}'Response:
{
"data": {
"magic_link": "https://app.getasset.com/ten_123456/biz_123456/reports/statements?token=...",
"magic_link_id": "mlk_123456"
}
}Send your customer to the magic_link, for example with a redirect from your backend.
| Attribute | Request Parameter | Description |
|---|---|---|
| Business | business_id or external_business_id | The Business to open. Use external_business_id if you identify Businesses by your own ID. The Business must be active. |
| The customer's email address. It identifies them in the app. | ||
| Path | path | Optional. The page to open, such as /reports/statements. Defaults to the Business's home page. |
| Link Lifetime | ttl | How long the link stays valid, in minutes. Default 5, maximum 15. |
| Session Length | session_timeout | How long the customer stays signed in, in seconds. Default 86400 (one day). |
Each link works once. Create it when the customer clicks, not in advance, and never email or store it.
Create the link on your server, after you have checked that the person is signed in to your platform and is allowed to see this Business. The link gives whoever opens it access to the Business's books.
Open a specific page
Use path to send a customer straight to the page they need. For example:
| Path | Page |
|---|---|
/reports/statements | Financial statements |
/transactions/bank-accounts | Bank account transactions |
/accounts | Connected accounts |
/documents | Documents |
Which pages exist depends on the Business's plan and on the features enabled for your Tenant. Use the path only, without a query string, because anything after a ? is dropped.
When a session ends
A session lasts as long as session_timeout, and doesn't extend while the customer is working. When it ends, the customer is sent to the Magic Link page you set in Set Up Your Tenant.
Customers can also arrive at your Asset domain without a session, for example from a bookmark or after a session ends. Asset sends them to your login page, and your platform signs them in with a new magic link.
The simplest approach is to make that page the same route you use to open accounting:
- The customer arrives at your route.
- Your route checks they are signed in to your platform.
- It creates a new magic link for their Business and redirects to it.
The customer lands back in the app, usually without noticing. If the link has expired or was already used, the app shows an error, so send the customer back to your route to get a new one.
Sign a customer out
The app doesn't show a sign-out button to customers who came through a magic link. They leave through the link back to your platform, which uses the Redirect URL from your domain settings.
To end sessions yourself, for example when a user is removed from your platform, call Logout a user with auth:delete scope:
curl --request POST \
--url https://api.sandbox.getasset.com/v0/auth/logout \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '{ "email": "jack@example.com" }'This ends every session for that email address. Pass session_id with the magic_link_id from the response above to end only one.
Sandbox
Use your sandbox credentials and the sandbox API URL to create links while you build. Sandbox links open in the Asset app, just like production ones. Switch to your production credentials and URL when you go live.