open-index/open-npm huggingface dataset:
npm package: @hashubo/auth-core
Description: Core OAuth 2.0 client for Hashub Auth
Latest version: 0.1.0

# @wop-sso/core

Core OAuth 2.0 client library for WOP-SSO integration.

## Features

- ✅ OAuth 2.0 Authorization Code Flow with PKCE
- ✅ Token management (access, refresh, ID tokens)
- ✅ User info retrieval
- ✅ Token refresh
- ✅ TypeScript support
- ✅ Zero dependencies

## Installation

```bash
pnpm add @wop-sso/core
# or
npm install @wop-sso/core
# or
yarn add @wop-sso/core
```

## Usage

```typescript
import { SSOClient } from '@wop-sso/core';

const client = new SSOClient({
  clientId: 'your-client-id',
  clientSecret: 'your-client-secret',
  ssoUrl: 'https://sso.your-domain.com', // optional
});

// Get authorization URL
const { url, codeVerifier } = await client.getAuthorizationUrl(
  'http://localhost:3000/callback',
  'random-state'
);

// Redirect user to authorization URL
// After callback with code:

// Exchange code for tokens
const tokens = await client.exchangeCodeForTokens(
  code,
  codeVerifier,
  'http://localhost:3000/callback'
);

// Get user info
const user = await client.getUserInfo(tokens.access_token);

// Refresh access token
const newTokens = await client.refreshAccessToken(tokens.refresh_token);
```

## API

### `SSOClient`

Main client class for OAuth operations.

#### Constructor

```typescript
new SSOClient(config: SSOConfig)
```

**Options:**
- `clientId` (string, required): OAuth client ID
- `clientSecret` (string, required): OAuth client secret
- `ssoUrl` (string, optional): SSO server URL. Default: `http://localhost:3003`
- `scopes` (string[], optional): OAuth scopes. Default: `['openid', 'email', 'profile']`

#### Methods

**`getAuthorizationUrl(redirectUri, state?)`**

Generate authorization URL for OAuth flow.

Returns: `{ url: string, codeVerifier: string }`

**`exchangeCodeForTokens(code, codeVerifier, redirectUri)`**

Exchange authorization code for access tokens.

Returns: `Promise<SSOTokens>`

**`refreshAccessToken(refreshToken)`**

Refresh access token using refresh token.

Returns: `Promise<SSOTokens>`

**`getUserInfo(accessToken)`**

Get user information from access token.

Returns: `Promise<SSOUser>`

**`revokeToken(token, tokenType?)`**

Revoke access or refresh token.

Returns: `Promise<void>`

## Types

```typescript
interface SSOConfig {
  clientId: string;
  clientSecret: string;
  ssoUrl?: string;
  scopes?: string[];
}

interface SSOTokens {
  access_token: string;
  refresh_token?: string;
  id_token?: string;
  token_type: string;
  expires_in: number;
  scope?: string;
}

interface SSOUser {
  sub: string;
  email: string;
  email_verified?: boolean;
  name?: string;
  picture?: string;
  [key: string]: any;
}
```

## License

MIT