createUserAuth() function
Generate a UserAuth containing API key, signature, and message.
The gRPC APIs will throw (or return an authorization error) if the message date has passed. This function should NOT be used client-side, as it requires a key secret. The result does not contain the secret and therefor CAN be used client side.
Signature:
export declare function createUserAuth(key: string, secret: string, date?: Date, token?: string): Promise<UserAuth>;
Parameters
Parameter | Type | Description |
---|---|---|
key | string | The API key secret to generate the signature. See KeyInfo for details. |
secret | string | The API key secret to generate the signature. See KeyInfo for details. |
date | Date | An optional future Date to use as signature message. Default 1 minute from now. |
token | string | An optional user API token. |
Returns:
Promise<UserAuth>
Example
Create a new UserAuth
import {createUserAuth, KeyInfo, UserAuth} from '@textile/hub';
async function auth (keyInfo: KeyInfo) {
// Create an expiration and create a signature. 60s or less is recommended.
const expiration = new Date(Date.now() + 60 * 1000)
// Generate a new UserAuth
const userAuth: UserAuth = await createUserAuth(keyInfo.key, keyInfo.secret ?? '', expiration)
return userAuth
}