The simplest way to create Xkit tokens for your users is to provision them using the Xkit Platform API.
Use the Provision Platform User endpoint with an active API Key.
The only data you need to provide is an external_id
- an identifier that uniquely identifies the user in your systems.
A simple example with an ExpressJS server follows.
Provision a user
On your server, when a user has authenticated, call this endpoint with your system's user ID as the external_id
parameter.
// `app` is a configured Express App with authentication middleware
// that provides the `req.user` parameter for authenticated users.
import axios from 'axios'
app.use(async (req, res) => {
if (!req.user) return
const { access_token } = await axios({
baseUrl: 'https://app.xkit.co/api/platform',
method: 'post',
url: '/users',
auth: {
username: "your_publishable_key",
password: "your_secret_key"
},
data: {
user: {
external_id: req.user.id,
// Optional Group
external_group_id: req.user.group_id
}
}
})
res.locals.xkitToken = access_token
})
Provide the token to the front-end
Retrieve the returned access_token
and provide it to your front-end (e.g. by rendering it in HTML or by providing it via an API call)
app.get('/home', (req, res) => {
res.render('home')
})
Log the user into Xkit
Use the access_token
with the xkit.js library on the front-end to authenticate the user.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>My App</title>
</head>
<body>
<script src="https://myapp.xkit.co/xkit.js"></script>
<script>xkit.ready(() => xkit.login("{{ xkitToken }}"))</script>
</body>
</html>
See the Hosted Integration Catalog for more examples of what to do with the Xkit User Token.
Updated 3 months ago
What's Next
Overview |