npm package: @finsel-dgi/pasby-react
Description: This is a javascript library for implementing authentication and authorization in react apps with pasby,
Author: cjackmay
Latest version: 0.1.4

This documentation includes installation instructions, basic usage, and a brief overview of the main components and functions.

# @finsel-dgi/pasby-react

`@finsel-dgi/pasby-react` is a React-focused software development kit (SDK) designed to facilitate authentication processes using the Pasby authorization server. This library provides tools to manage user authentication flows, handle tokens, and interact with the Pasby API.

## Installation

To install `@finsel-dgi/pasby-react`, use [npm](https://www.npmjs.com/) or [yarn](https://yarnpkg.com/):

```bash
npm install @finsel-dgi/pasby-react
```

or

```bash
yarn add @finsel-dgi/pasby-react
```

## Usage

### Importing the Library

To use the library, import the necessary functions and components into your React application:

```javascript
import { handshake, User } from '@finsel-dgi/pasby-react';
```

### Authentication Flow

The primary function of this library is to manage the authentication flow with the Pasby authorization server. Below is an example of how to initiate a handshake process:

```javascript
import { handshake } from '@finsel-dgi/pasby-react';

async function initiateHandshake(flow, code, pkceVerifier) {
  try {
    const response = await handshake({ flow, code, pkceVerifier });
    console.log('Access Token:', response.access);
    console.log('Challenge:', response.challenge);
  } catch (error) {
    console.error('Error during handshake:', error);
  }
}
```

### User Data

The library provides a `User` interface to define the structure of user data. This can be used to manage and type-check user information within your application:

```typescript
import { User } from '@finsel-dgi/pasby-react';

const user: User = {
  national: '123456789',
  country: 'CountryName',
  claims: {
    contact: {
      email: 'user@example.com',
      phone: '123-456-7890',
      emailVerified: true,
      phoneVerified: false,
    },
    address: {
      country: 'CountryName',
      city: 'CityName',
      countryCode: 'CN',
      formatted: '123 Main St, CityName, CountryName',
      postCode: '12345',
      place: 'PlaceName',
    },
    bio: {
      birthdate: '1990-01-01',
      gender: 'Non-binary',
      birthplace: 'CityName',
      birthnumber: 123456789,
      maritalStatus: 'Single',
      age: 34,
    },
    nationality: {
      pep: false,
      nationalities: ['CountryName'],
      residence: 'CityName',
      primary: 'CountryName',
    },
  },
};
```

## API Reference

### `handshake(params: { flow: string, code: string, pkceVerifier: string }): Promise<{ exp: number, access: string, challenge: string }>`

- **Description**: Initiates a handshake process with the Pasby authorization server.
- **Parameters**:
  - `flow`: The flow query value received by the redirect from the Pasby authorization server.
  - `code`: The handshake query value received by the redirect from the Pasby authorization server.
  - `pkceVerifier`: The PKCE verifier parsed to you when the login link was created.
- **Returns**: A promise that resolves to an object containing the expiration time (`exp`), access token (`access`), and challenge (`challenge`).

## Contributing

Contributions are welcome! Please feel free to submit a pull request or open an issue for any bugs or feature requests.

## License

This project is licensed under the MIT License. See the [LICENSE](LICENSE) file for details.


This documentation provides a basic overview of how to use the `@finsel-dgi/pasby-react` library, including installation, usage examples, and API references. Adjust the content as necessary to fit any additional features or changes in your library.