# DWGingerBundle API Documentation




## Installation

#### 1. Add firewalls for oauth token generation and api
```yaml
# /config/packages/security.yaml
security:
    firewalls:
        # ...
        oauth_token:
            pattern:    ^/api/oauth/v2/token
            security:   false
        api:
            pattern:    ^/api/graphql
            fos_oauth:  true
            stateless:  true
            anonymous:  false
    
    access_control:
        # ...
        - { path: ^/api/oauth, roles: [ IS_AUTHENTICATED_ANONYMOUSLY ] }
        - { path: ^/api/graphql, roles: [ IS_AUTHENTICATED_FULLY ] }
```

## Getting started

#### 1. Create a client
At the moment we only support to create clients with grant type password and / or refresh_token. This allows to access
the API with client_id, client_secret username and password.  

```bash
bin/console fos:oauth-server:create --grant-type=password --grant-type=refresh_token
```

#### 2. Obtain an access token for this client and a given user
```bash
http get http://127.0.0.1:8000/api/oauth/v2/token?grant_type=password&client_id={CLIENT_ID}&client_secret={CLIENT_ID}&username={USERNAME}&password={PASSWORD}
``` 

This returns:
```josn
{
  "access_token": "NGRkNDM0NTU3NzU5YjlmOTJmNzkzNjI5Mzc2NDYxNzExZGM0MDc2OTE5NzZkMTM1ODI3MmM0Y2I0MWRjYzA4ZA",
  "expires_in": 3600,
  "token_type": "bearer",
  "scope": null,
  "refresh_token": "NmUyODZjNDE1NDYzMDM0ODkxYTUwNmRjMzU1MDY4NjcwMzQ2YjA3ZmIzMDc2NzhkZjA1N2QyNjkzMTUyZDZiOA"
}
``` 
 

#### 3. Call the API with this token
```bash
# Authentication Header: Bearer {ACCESS_TOKEN}
http post http://127.0.0.1:8000/api/graphql
``` 

### Optional: Get a new token by using the refresh token
```bash
http get http://127.0.0.1:8000/api/oauth/v2/token?grant_type=refresh_token&client_id={CLIENT_ID}&client_secret={CLIENT_SECRET}&username={USERNAME}&refresh_token={REFRESH_TOKEN}
```