Getting Stored OAuth Tokens and User Information
Cotter's SDK automatically stores the returned access_token, id_token , refresh_token and user information in the device's secure storage when the user successfully authenticates.

Get Access Token

This function automatically refreshes the access token when needed.
1
const getAccessToken = async () => {
2
var cotter = new Cotter(API_KEY_ID);
3
try {
4
var accessToken = await cotter.tokenHandler.getAccessToken();
5
console.log('Access Token', accessToken);
6
} catch (err) {
7
console.log('Access Token Error', err);
8
}
9
};
Copied!

Get ID Token

This function automatically refreshes the id token when needed.
1
const getIDToken = async () => {
2
var cotter = new Cotter(API_KEY_ID);
3
try {
4
var idToken = await cotter.tokenHandler.getIDToken();
5
console.log('ID Token', idToken);
6
} catch (err) {
7
console.log('ID Token Error', err);
8
}
9
};
Copied!

Get Logged-in User

JavaScript
User Object
1
const getLoggedInUser = async () => {
2
var cotter = new Cotter(API_KEY_ID);
3
try {
4
let user = await cotter.getLoggedInUser();
5
} catch(err) {
6
console.log('Get user error', err);
7
}
8
};
Copied!
1
class User {
2
ID: string; // Cotter User ID
3
issuer: string;
4
client_user_id: string;
5
enrolled: string[];
6
identifier: string;
7
}
Copied!

Log Out

JavaScript
1
const logOut = async () => {
2
var cotter = new Cotter(API_KEY_ID);
3
try {
4
await cotter.logOut();
5
} catch (err) {
6
console.log(err);
7
}
8
};
Copied!

OAuth Token Specification

​