Skip to content

Commit

Permalink
update README + run prettier
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexCuse committed Dec 12, 2023
1 parent abca705 commit 28e5b90
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 13 deletions.
22 changes: 21 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,8 @@ KeratinAuthN.signup(obj: {username: string, password: string}): Promise<void>
```javascript
// Returns a Promise that is fulfilled when a successful login has established a session.
// May error with generic validation failures.
KeratinAuthN.login(obj: {username: string, password: string}): Promise<void>
// OTP is only used in v1.18 and forward.
KeratinAuthN.login(obj: {username: string, password: string, otp: string}): Promise<void>
```

```javascript
Expand Down Expand Up @@ -139,6 +140,25 @@ KeratinAuthN.requestSessionToken(username: string): Promise<>
KeratinAuthN.sessionTokenLogin(obj: {token: string}): Promise<void>
```

```javascript
// Creates a new TOTP code for the logged in user. Returns an object containing the raw secret and
// TOTP onboarding URL.
// Only available in authn-server v1.18 and forward.
KeratinAuthN.newTOTP(obj: {token: string}): Promise<OtpData>
```

```javascript
// Confirms a pending TOTP code for the authenticated user.
// Only available in authn-server v1.18 and forward.
KeratinAuthN.confirmTOTP(obj: {otp: string}): Promise<boolean>
```

```javascript
// Deletes a confirmed TOTP code for the authenticated user.
// Only available in authn-server v1.18 and forward.
KeratinAuthN.deleteTOTP(): Promise<boolean>
```

## Development

Embrace the TypeScript!
Expand Down
20 changes: 8 additions & 12 deletions src/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,24 +105,20 @@ export function sessionTokenLogin(credentials: {
);
}

export function newTOTP() : Promise<OtpData> {
return post<OtpData>(url("/totp/new"), {}).then(
(result: OtpData) => result
)
export function newTOTP(): Promise<OtpData> {
return post<OtpData>(url("/totp/new"), {}).then((result: OtpData) => result);
}

export function confirmTOTP(req: {
otp: string;
}) : Promise<boolean> {
export function confirmTOTP(req: { otp: string }): Promise<boolean> {
return post<void>(url("/totp/confirm"), req)
.then(() => true)
.catch(() => false);
.then(() => true)
.catch(() => false);
}

export function deleteTOTP() : Promise<boolean> {
export function deleteTOTP(): Promise<boolean> {
return del<void>(url("/totp"))
.then(() => true)
.catch(() => false);
.then(() => true)
.catch(() => false);
}

function url(path: string): string {
Expand Down

0 comments on commit 28e5b90

Please sign in to comment.