This commit is contained in:
42
nhncloud/packages/ApiToken.py
Normal file
42
nhncloud/packages/ApiToken.py
Normal file
@ -0,0 +1,42 @@
|
||||
import requests
|
||||
import json
|
||||
|
||||
|
||||
# def createToken(url, parms):
|
||||
def createToken(parms):
|
||||
url = "https://api-identity-infrastructure.nhncloudservice.com/v2.0/tokens"
|
||||
response = requests.post(url, json=parms) # 응답요청
|
||||
|
||||
datas = json.loads(response.text)
|
||||
# print(datas)
|
||||
if "error" in datas:
|
||||
errDict = {
|
||||
'state' : 'err',
|
||||
'code' : datas['error']['code'],
|
||||
'errTitle' : datas['error']['title'],
|
||||
'errMsg' : datas['error']['message']
|
||||
}
|
||||
return errDict
|
||||
else:
|
||||
getDict = {
|
||||
'state' : 'steady',
|
||||
'tokenValue' : datas['access']['token']['id']
|
||||
}
|
||||
# WhatToken = getDict['tokenValue']
|
||||
return getDict
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
# 예제 내용
|
||||
url = "https://api-identity-infrastructure.nhncloudservice.com/v2.0/tokens"
|
||||
parms = {
|
||||
"auth": {
|
||||
"tenantId": "04a2c5b7de7e4d66b970ad950081a7c3", # kr2
|
||||
"passwordCredentials": {
|
||||
# "username": "sdjo@injeinc.co.kr",
|
||||
# "password": "ijinc123!"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
print(createToken(url, parms))
|
Reference in New Issue
Block a user