Spaces:
Sleeping
Sleeping
File size: 1,049 Bytes
eef6aa0 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
import os
import requests
def get_token():
username = os.environ["USER_NAME"]
domain_name = os.environ["DOMAIN_NAME"]
domain_pwd = os.environ["DOMAIN_PWD"]
url = os.environ["IAM_URL"]
requests_json = {
"auth": {
"identity": {
"methods": ["password"],
"password": {
"user": {
"name": username,
"password": domain_pwd,
"domain": {
"name": domain_name
}
}
}
},
"scope": {
"project": {
"name": "cn-central-221"
}
}
}
}
headers = {
"Content-Type": "application/json"
}
response = requests.post(url, json=requests_json, headers=headers)
result = response.headers
print("token success")
return result['X-Subject-Token']
if __name__ == "__main__":
get_token()
|