Skip to content

Commit

Permalink
Support basic authentication
Browse files Browse the repository at this point in the history
  • Loading branch information
lqmanh committed Aug 8, 2020
1 parent f9ee777 commit 1e8166d
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
@@ -1,5 +1,11 @@
## CHANGELOG

### Unreleased

#### Features

- Support basic authentication

### v0.1.1

#### Bugfixes
Expand Down
8 changes: 8 additions & 0 deletions README.md
Expand Up @@ -4,6 +4,14 @@ PostgREST client for Python. This library provides an ORM interface to PostgREST

## INSTALLATION

### Requirements

- Python >= 3.7
- PostgreSQL >= 12
- PostgREST >= 7

### Instructions

## USAGE

## DOCUMENTATION
Expand Down
9 changes: 7 additions & 2 deletions postgrest_py/client.py
Expand Up @@ -22,8 +22,13 @@ async def __aexit__(self, exc_type, exc, tb) -> None:
async def aclose(self) -> None:
await self.session.aclose()

def auth(self, token: str):
self.session.headers["Authorization"] = f"Bearer {token}"
def auth(self, bearer_token: str, *, username: str = None, password=""):
"""Authenticate the request, with either bearer token or basic authentication."""

if username:
self.session.auth = (username, password)
else:
self.session.headers["Authorization"] = f"Bearer {bearer_token}"
return self

def schema(self, schema: str):
Expand Down

0 comments on commit 1e8166d

Please sign in to comment.