File: utils.py

package info (click to toggle)
python-django-rest-framework-guardian 0.4.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 136 kB
  • sloc: python: 267; makefile: 7; sh: 6
file content (9 lines) | stat: -rw-r--r-- 309 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
from base64 import b64encode

from rest_framework import HTTP_HEADER_ENCODING


def basic_auth_header(username, password):
    credentials = ('%s:%s' % (username, password))
    credentials = credentials.encode(HTTP_HEADER_ENCODING)
    return 'Basic %s' % b64encode(credentials).decode(HTTP_HEADER_ENCODING)