|
| 1 | +// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. |
| 2 | + |
| 3 | +import { APIResource } from '../../core/resource'; |
| 4 | +import { APIPromise } from '../../core/api-promise'; |
| 5 | +import { RequestOptions } from '../../internal/request-options'; |
| 6 | + |
| 7 | +/** |
| 8 | + * Inspect the identity and authorization context for the current request. |
| 9 | + */ |
| 10 | +export class Context extends APIResource { |
| 11 | + /** |
| 12 | + * Returns the authenticated principal, organization, credential scope, and |
| 13 | + * effective request scope. The response is derived from the verified request |
| 14 | + * context and does not expose credential secrets. |
| 15 | + * |
| 16 | + * @example |
| 17 | + * ```ts |
| 18 | + * const authContext = await client.auth.context.retrieve(); |
| 19 | + * ``` |
| 20 | + */ |
| 21 | + retrieve(options?: RequestOptions): APIPromise<AuthContext> { |
| 22 | + return this._client.get('/auth/context', options); |
| 23 | + } |
| 24 | +} |
| 25 | + |
| 26 | +/** |
| 27 | + * The identity and authorization context resolved for the current request. |
| 28 | + */ |
| 29 | +export interface AuthContext { |
| 30 | + authentication: AuthContext.Authentication; |
| 31 | + |
| 32 | + /** |
| 33 | + * The credential's maximum scope and the effective scope selected for this |
| 34 | + * request. Future permission data can be added without changing scope semantics. |
| 35 | + */ |
| 36 | + authorization: AuthContext.Authorization; |
| 37 | + |
| 38 | + organization: AuthContext.Organization; |
| 39 | + |
| 40 | + principal: AuthContext.Principal; |
| 41 | +} |
| 42 | + |
| 43 | +export namespace AuthContext { |
| 44 | + export interface Authentication { |
| 45 | + /** |
| 46 | + * The API key ID when authenticated with an API key; null for session credentials. |
| 47 | + */ |
| 48 | + credential_id: string | null; |
| 49 | + |
| 50 | + /** |
| 51 | + * The credential format used to authenticate the request. |
| 52 | + */ |
| 53 | + method: 'api_key' | 'jwt'; |
| 54 | + |
| 55 | + /** |
| 56 | + * The source classification resolved by authentication middleware. |
| 57 | + */ |
| 58 | + source: 'api_key' | 'oauth' | 'dashboard'; |
| 59 | + } |
| 60 | + |
| 61 | + /** |
| 62 | + * The credential's maximum scope and the effective scope selected for this |
| 63 | + * request. Future permission data can be added without changing scope semantics. |
| 64 | + */ |
| 65 | + export interface Authorization { |
| 66 | + /** |
| 67 | + * A scope within the authenticated organization. A null project_id represents |
| 68 | + * organization-wide scope. |
| 69 | + */ |
| 70 | + credential_scope: Authorization.CredentialScope; |
| 71 | + |
| 72 | + /** |
| 73 | + * A scope within the authenticated organization. A null project_id represents |
| 74 | + * organization-wide scope. |
| 75 | + */ |
| 76 | + effective_scope: Authorization.EffectiveScope; |
| 77 | + } |
| 78 | + |
| 79 | + export namespace Authorization { |
| 80 | + /** |
| 81 | + * A scope within the authenticated organization. A null project_id represents |
| 82 | + * organization-wide scope. |
| 83 | + */ |
| 84 | + export interface CredentialScope { |
| 85 | + /** |
| 86 | + * The Kernel project ID, or null when the scope is organization-wide. |
| 87 | + */ |
| 88 | + project_id: string | null; |
| 89 | + } |
| 90 | + |
| 91 | + /** |
| 92 | + * A scope within the authenticated organization. A null project_id represents |
| 93 | + * organization-wide scope. |
| 94 | + */ |
| 95 | + export interface EffectiveScope { |
| 96 | + /** |
| 97 | + * The Kernel project ID, or null when the scope is organization-wide. |
| 98 | + */ |
| 99 | + project_id: string | null; |
| 100 | + } |
| 101 | + } |
| 102 | + |
| 103 | + export interface Organization { |
| 104 | + /** |
| 105 | + * The authenticated Kernel organization ID. |
| 106 | + */ |
| 107 | + id: string; |
| 108 | + } |
| 109 | + |
| 110 | + export interface Principal { |
| 111 | + /** |
| 112 | + * The API key ID for API-key principals or user ID for user principals. |
| 113 | + */ |
| 114 | + id: string; |
| 115 | + |
| 116 | + /** |
| 117 | + * The kind of principal authenticated for the request. |
| 118 | + */ |
| 119 | + type: 'api_key' | 'user'; |
| 120 | + } |
| 121 | +} |
| 122 | + |
| 123 | +export declare namespace Context { |
| 124 | + export { type AuthContext as AuthContext }; |
| 125 | +} |
0 commit comments