Skip to content

Using Basic Auth username & password for posting RPMs

marshyski edited this page Oct 7, 2014 · 3 revisions

Example usage:
curl -u timski:FastForward4149 -F [email protected] http://localhost/api/upload

Gist: https://gist.githubusercontent.com/marshyski/ff4a9865ae3ed76cee66/raw/dce106b723f75dee2b414c809e584f5dd0a1ec38/yum-nginx-api-basic-auth.py

Additions to requirements.txt:

Flask-HTTPAuth==2.2.1

Additions to init.py:

from flask import Flask, request, jsonify, make_response
from flask.ext.httpauth import HTTPBasicAuth

# Under app =
auth = HTTPBasicAuth()

# Under app.config
@auth.get_password
def get_password(username):
    if username == 'timski':
       return 'FastForward4149'
    return None

@auth.error_handler
def unauthorized():
    return make_response(jsonify(message='Unauthorized Access', status=403), 403)

#Under app.route /api/upload
@auth.login_required