| 1 | import type { Result } from "./result"; |
| 2 | |
| 3 | export type User = { id: string; username: string }; |
| 4 | |
| 5 | /** Who is asking. Every read and write in every service takes one. */ |
| 6 | export type Viewer = User | null; |
| 7 | |
| 8 | export type SshKey = { |
| 9 | id: string; |
| 10 | title: string; |
| 11 | fingerprint: string; |
| 12 | createdAt: number; |
| 13 | }; |
| 14 | |
| 15 | export type AccessToken = { id: string; name: string; createdAt: number }; |
| 16 | |
| 17 | /** Accounts, credentials and sessions. */ |
| 18 | export interface IdentityApi { |
| 19 | /** Verifies a username and password for website sign-in. */ |
| 20 | signIn(username: string, password: string): Promise<Result<{ user: User; sessionToken: string }>>; |
| 21 | signOut(sessionToken: string): Promise<void>; |
| 22 | userForSession(sessionToken: string): Promise<Viewer>; |
| 23 | |
| 24 | /** Verifies git credentials: the account password or an access token. */ |
| 25 | userForGitCredentials(username: string, secret: string): Promise<Viewer>; |
| 26 | userForSshKey(fingerprint: string): Promise<Viewer>; |
| 27 | userByUsername(username: string): Promise<Viewer>; |
| 28 | |
| 29 | listSshKeys(user: User): Promise<SshKey[]>; |
| 30 | /** Takes one line in OpenSSH public key format. */ |
| 31 | addSshKey(user: User, title: string, publicKey: string): Promise<Result<SshKey>>; |
| 32 | removeSshKey(user: User, id: string): Promise<void>; |
| 33 | |
| 34 | listAccessTokens(user: User): Promise<AccessToken[]>; |
| 35 | /** The plaintext token is returned once and never stored. */ |
| 36 | createAccessToken(user: User, name: string): Promise<{ token: string; info: AccessToken }>; |
| 37 | removeAccessToken(user: User, id: string): Promise<void>; |
| 38 | } |