npm package: @rapharacing/auth-utils
Description: Auth Utils
Author: Rapha Racing
Latest version: 0.0.3

# Rapha Auth Utilities

Auth Utils

## Installation

`yarn add @rapharacing/auth-utils`

## How to use

```js
import * as utils from "@rapharacing/auth-utils";

import { getHeaders } from "@rapharacing/auth-utils";
```

## License

Design tokens are freely distributable under the terms of the [MIT license](https://github.com/rapharacing/design-tokens/blob/develop/Licence).

[license-image]: http://img.shields.io/badge/license-MIT-blue.svg?style=flat

[license-url]: https://github.com/moment/moment/blob/develop/LICENSE

## API

<!-- Generated by documentation.js. Update this documentation by updating the source code. -->

#### Table of Contents

-   [buildIAMPolicy](#buildiampolicy)
    -   [Parameters](#parameters)
-   [getUserTokens](#getusertokens)
    -   [Parameters](#parameters-1)
-   [setUserToken](#setusertoken)
    -   [Parameters](#parameters-2)
-   [updateUserToken](#updateusertoken)
    -   [Parameters](#parameters-3)
-   [decodeJWT](#decodejwt)
    -   [Parameters](#parameters-4)
-   [verifyJWT](#verifyjwt)
    -   [Parameters](#parameters-5)
-   [formatAuthorizationToken](#formatauthorizationtoken)
    -   [Parameters](#parameters-6)
-   [getHeaders](#getheaders)
    -   [Parameters](#parameters-7)
-   [authorizeUser](#authorizeuser)
    -   [Parameters](#parameters-8)

### buildIAMPolicy

Returns an IAM policy document for a given user and resource.

#### Parameters

-   `username` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** username
-   `effect` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** allow / deny
-   `resource` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** resource ARN
-   `context` **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** response context

Returns **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** policyDocument

### getUserTokens

Returns tokens from key value store

#### Parameters

-   `db` **DynamoDB** db
-   `table` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** table
-   `uid` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** uid
-   `client` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** client

Returns **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** tokens

### setUserToken

Sets tokens in key value store by uid and client

#### Parameters

-   `db` **DynamoDB** db
-   `table` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** table
-   `uid` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** uid
-   `client` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** client
-   `data` **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** data to set as the value in the store

### updateUserToken

Updates a users tokens in the key value store

#### Parameters

-   `db` **DynamoDB** db
-   `table` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** table
-   `uid` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** uid
-   `client` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** client
-   `data` **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** data to set as the value in the store

### decodeJWT

Returns decoded user data from JWT

#### Parameters

-   `token` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** jwt token
-   `secret` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** jwt secret depending on env

Returns **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** token

### verifyJWT

Returns verified user data from JWT

#### Parameters

-   `token` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** jwt token
-   `secret` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** jwt secret depending on env

Returns **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** token

### formatAuthorizationToken

Formats the Authorization Token

#### Parameters

-   `token` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** jwt token

Returns **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** token

### getHeaders

Get common headers depending on environment

#### Parameters

-   `headers` **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** headers to merge
-   `env` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** current environment

Returns **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** headers

### authorizeUser

Returns a boolean whether or not a user is allowed to call a particular method

#### Parameters

-   `userScopes` **[Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)** array of user scopes
-   `methodArn` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** methodArn

Returns **[Boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)**