# Flask extension for Atlas authorization

Provides functionality to use Atlas-UM authorization in Your flask projects

# Usage with flask projects

Provide the following settings by env or app config

```
ATLAS_LOGIN_URL
ATLAS_LOGOUT_URL
ATLAS_REFRESH_TOKEN_URL
ATLAS_PUBLIC_KEY_URL
ATLAS_ENCODING_ALGORITHM
ATLAS_RELATED_CLAIMS_NAMESPACE
ATLAS_REFRESH_TOKEN_COOKIE_NAME
ATLAS_TOKEN_COOKIES_MAX_AGE
```

Init the extension

```python
import flask
from flask_atlas_auth import AuthManager

app = flask.Flask("test_app")
auth_manager = AuthManager(app)
```

Create your claims

```python
from enum import Enum
from flask_atlas_auth.claims import BaseAuthClaim

class TestClaim(BaseAuthClaim):
    path = "test_path"
    value_field = "test_value_field"

    class Values(Enum):
        test_value1 = "test_value_external_1"
        test_value2 = "test_value_external_2"


class TestAudienceClaim(BaseAuthClaim):
    is_reserved = True
    path = "aud"
    value_field = None

    class Values(BaseAuthClaim.Values):
        api_read = "test_app|api_read"
```

Use decorators to limit the access to views

```python
from flask_atlas_auth.decorators import claims_required
from your_app.claims import TestClaim, TestAudienceClaim

@claims_required(
    [
      TestClaim(TestClaim.Values.test_value1), 
      TestAudienceClaim(TestAudienceClaim.Values.api_read)
    ],
    login_redirect=False,
)
```

## Building and pushing package

**1.** Create virtualenv.

```bash
$ virtualenv -p python3 venv
```

Set up .pypirc file
```bash
$ cp configs/.pypirc ~/.pypirc
$ chmod 600 ~/.pypirc
```

**2.** Install local dependencies.

```bash
$ source venv/bin/activate
$ pip install -r requirements/local.txt
```

**3.** Build package
Before this step make sure you changed package version in setup.py

```bash
$ python setup.py sdist bdist_wheel
```

**4.** Push package to private pip server

```bash
$ twine upload --repository pypi dist/*
```
