# @meistrari/auth-core

A TypeScript/JavaScript SDK for interacting with the Auth API service.

## Features

- **Multiple Authentication Methods**
  - Social providers (Google, Microsoft)
  - SAML-based SSO
  - Email and password
- **Organization Management**
  - Multi-tenant support
  - Role-based access control (RBAC)
  - Team management
  - Member invitations
- **JWT Token Validation**
- **Application Authentication**
  - OAuth PKCE application flows
  - OAuth Device Authorization Grant endpoints
  - OAuth Client Credentials Grant for service accounts
  - Organization-scoped application token caching, renewal, and retry handling
  - Application token refresh, logout, and organization switching
- **API Keys**
  - User-scoped API key CRUD
  - Active-organization API key listing

## Installation

```bash
bun add @meistrari/auth-core
```

## Quick Start

```typescript
import { AuthClient } from '@meistrari/auth-core'

// Initialize the client
const authClient = new AuthClient('https://auth.example.com')

// Sign in with email and password
await authClient.session.signInWithEmailAndPassword({
    email: 'user@example.com',
    password: 'SecurePassword123!'
})

// List user's organizations
const organizations = await authClient.organization.listOrganizations()
console.log('Organizations:', organizations)

// Application auth helpers
const { code } = await authClient.application.startAuthorizationFlow(
    'application-id',
    'https://your-app.com/auth/callback',
    'pkce-code-challenge',
    'organization-id',
)
const tokens = await authClient.application.completeAuthorizationFlow(code, 'pkce-code-verifier')
console.log('Application user:', tokens.user.email)
```

## Guides

- [Client Credentials Grant](https://github.com/meistrari/auth-api/blob/main/packages/core/docs/CLIENT_CREDENTIALS.md) — server-to-server authentication using the recommended `ApplicationTokenStorage` helper

## API Reference

See it on [Pantry](https://pantry.tela.tools/ingredients/auth-core/api)
