-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathpassword-auth.ts
More file actions
33 lines (26 loc) · 956 Bytes
/
password-auth.ts
File metadata and controls
33 lines (26 loc) · 956 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
/**
* Password Authentication Example
*
* Demonstrates connecting to Safeguard with username/password,
* fetching the current user, and disconnecting.
*/
import { SafeguardClient, PasswordAuth, Service } from '@oneidentity/safeguard';
const host = 'safeguard.sample.corp';
const username = 'MyUser';
const password = 'MyPassword';
const provider = 'Local';
async function main() {
const client = new SafeguardClient(host, {
auth: new PasswordAuth({ username, password, provider }),
// To disable TLS verification for self-signed certs (dev only):
// verify: false,
});
await client.connect();
console.log('Connected!');
const me = await client.get<{ DisplayName: string }>(Service.CORE, 'Me');
console.log('Current user:', me.DisplayName);
const remaining = client.getAccessTokenLifetimeRemaining();
console.log(`Token lifetime remaining: ${remaining}s`);
await client.disconnect();
}
main().catch(console.error);