implement api auth method
This commit is contained in:
parent
703076b27d
commit
7999bf5859
|
@ -1,2 +1,34 @@
|
||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
|
"""API client to core-networks"""
|
||||||
|
|
||||||
|
import requests
|
||||||
|
import os
|
||||||
|
import json
|
||||||
|
import urlparse
|
||||||
|
|
||||||
|
|
||||||
|
def api_auth(user, passwd, host):
|
||||||
|
data = {}
|
||||||
|
data["login"] = user
|
||||||
|
data["password"] = passwd
|
||||||
|
json_data = json.dumps(data)
|
||||||
|
|
||||||
|
url = urlparse.urljoin(host, "auth", "token")
|
||||||
|
r = requests.post(url, data=json_data)
|
||||||
|
return r
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
"""Main logic entrypoint"""
|
||||||
|
API_HOST = "https://beta.api.core-networks.de/"
|
||||||
|
API_USER = "your.email@example.com"
|
||||||
|
PASSWORD = "secret"
|
||||||
|
|
||||||
|
auth_token = r.json()
|
||||||
|
print auth_token
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
||||||
|
|
Reference in New Issue
Block a user