# Session Service

## Request

If you only require Session API functionality, you can import the module separately to the main SDK.

For example:

```javascript
const { Session } = require('n-membership-sdk');
const sessionSDK = new Session(config);
```

## Table of Contents

* [Session Service](#session-service)
  * [Request](#request)
  * [Table of Contents](#table-of-contents)
  * [Config](#config)
    * [How to obtain a key](#how-to-obtain-a-key)
  * [Methods](#methods)
    * [createSessionToken](#createsessiontoken)
    * [createSecureSessionToken](#createsecuresessiontoken)
    * [fetchSessionInfo](#fetchsessioninfo)
  * [Documentation](#documentation)

## Config

* See common configuration options in the [README file](./README.doc)
* `sessionApiKey` - Needed for [`createSessionToken`](#createsessiontoken) and [`createSecureSessionToken`](#createsecuresessiontoken).

```javascript
const config = new ProductionConfiguration({
	sessionApiKey: 'secret'
});
```

### How to obtain a key

To obtain a key, do one of the following:

1. Check in Doppler for your app to see if a session service API key already exists.
2. Contact #membership-support slack channel for a session service API key.

## Methods

### createSessionToken

- Creates a session token

```javascript
const sessionToken = sessionSDK.createSessionToken(userId);
```

| Parameters    | Required | Type   | Example | Description   |
| ------------- | -------- | -------| --------| ------------- |
| userId        | Yes      | String | xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx | User's uuid   |

**Response**:
`String`
```
09Svry7yZUA_07-wnwiVCnPFzwAAAW7MecEow8I.MEYCIQDuxuj7aJdSsEwbnuY0J4gx_9yzNHTyWunRaZhrCtPJPwIhAJFW4P2Q96YIUVC9X4ipm7F817xXbCJTg8k1sdxf3e8c
```

### createSecureSessionToken

- Creates a secure session token

```javascript
const secureSessionToken = sessionSDK.createSecureSessionToken(userId);
```

| Parameters    | Required | Type   | Example | Description   |
| ------------- | -------- | -------| --------| ------------- |
| userId        | Yes      | String | xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx | User's uuid   |

**Response**:
`String`
```
09Svry7yZUA_07-wnwiVCnPFzwAAAW7MecEow8I.MEYCIQDuxuj7aJdSsEwbnuY0J4gx_9yzNHTyWunRaZhrCtPJPwIhAJFW4P2Q96YIUVC9X4ipm7F817xXbCJTg8k1sdxf3e8c
```

### fetchSessionInfo

- Returns information about the current secure session

```javascript
const sessionInformation = sessionSDK.fetchSessionInfo(secureSessionId);
```

| Parameters    | Required | Type   | Example | Description   |
| ------------- | -------- | -------| --------| ------------- |
| secureSessionId        | Yes      | String | xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx | ID of a secure session   |

**Response**:
`Object`
```
{
  creationTime: '1575555032068',
  mfa: false,
  rememberMe: true,
  uuid: 'mock-user-id'
}
```

## Documentation

| Documentation     | Description | Owner |
| -------------- | -------- | -------- |
| [Session API](https://session-api.memb.ft.com/swagger-ui/) | Documentation for the Session API | FT Core - Membership |
