@textile/hub > Users > getTokenChallenge
Users.getTokenChallenge() method
Obtain a token for interacting with the remote API. When your app is creating new private-key based users to interact with the API using User Group keys, you must first create a new token for each new user. Tokens do not change after you create them. This callback method will require you to handle challenge signing.
Signature:
getTokenChallenge(publicKey: string, callback: (challenge: Uint8Array) => Uint8Array | Promise<Uint8Array>): Promise<string>;
Parameters
Parameter | Type | Description |
---|---|---|
publicKey | string | |
callback | (challenge: Uint8Array) => Uint8Array | Promise<Uint8Array> | A callback function that takes a challenge argument and returns a signed message using the input challenge and the private key associated with publicKey . publicKey must be the corresponding public key of the private key used in callback . |
Returns:
Promise<string>
Example
import { Users, PrivateKey } from '@textile/hub'
async function example (users: Users, identity: PrivateKey) {
const token = await users.getTokenChallenge(
identity.public.toString(),
(challenge: Uint8Array) => {
return new Promise((resolve, reject) => {
// This is where you should program PrivateKey to respond to challenge
// Read more here: https://docs.textile.io/tutorials/hub/production-auth/
})
}
)
return token
}