First Commit
This commit is contained in:
parent
53304d6196
commit
897e9c33a1
|
@ -14,8 +14,12 @@ class IAMExample:
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.iamURL = 'https://accounts.dev.d4science.org/auth/realms/d4science/protocol/openid-connect/token'
|
self.iamURL = 'https://accounts.dev.d4science.org/auth/realms/d4science/protocol/openid-connect/token'
|
||||||
self.call = sys.argv[1]
|
self.call = sys.argv[1]
|
||||||
|
self.clientId = sys.argv[2]
|
||||||
|
self.secret = sys.argv[3]
|
||||||
print('Call: ' + self.call)
|
print('Call: ' + self.call)
|
||||||
|
print('ClientId: ' + self.clientId)
|
||||||
|
print('Secret: ' + self.secret)
|
||||||
|
|
||||||
def main(self):
|
def main(self):
|
||||||
if self.call== "AccessToken":
|
if self.call== "AccessToken":
|
||||||
self.getAccessToken()
|
self.getAccessToken()
|
||||||
|
@ -27,47 +31,33 @@ class IAMExample:
|
||||||
|
|
||||||
def getAccessToken(self):
|
def getAccessToken(self):
|
||||||
print("getAccessToken()")
|
print("getAccessToken()")
|
||||||
self.clientId = sys.argv[2]
|
|
||||||
self.secret = sys.argv[3]
|
|
||||||
print('ClientId: ' + self.clientId)
|
|
||||||
print('Secret: ' + self.secret)
|
|
||||||
|
|
||||||
loginheaders = { 'Accept' : 'application/json', 'Content-Type' : 'application/x-www-form-urlencoded'}
|
loginheaders = { 'Accept' : 'application/json', 'Content-Type' : 'application/x-www-form-urlencoded'}
|
||||||
logindata = { 'grant_type' : 'client_credentials', 'client_id' : self.clientId, 'client_secret' : self.secret}
|
logindata = { 'grant_type' : 'client_credentials', 'client_id' : self.clientId, 'client_secret' : self.secret}
|
||||||
|
|
||||||
# login with offline_token
|
# Get Access Token by client_id
|
||||||
resp1 = requests.post(self.iamURL, data=logindata, headers=loginheaders)
|
resp1 = requests.post(self.iamURL, data=logindata, headers=loginheaders)
|
||||||
jwt1 = resp1.json()
|
jwt1 = resp1.json()
|
||||||
print("Resp1: ",jwt1)
|
print("Resp1: ",jwt1)
|
||||||
return jwt1["access_token"]
|
accessToken=jwt1["access_token"]
|
||||||
|
return accessToken
|
||||||
|
|
||||||
|
|
||||||
def getUmaToken(self):
|
def getUmaToken(self):
|
||||||
print("getUmaToken()")
|
print("getUmaToken()")
|
||||||
self.clientId = sys.argv[2]
|
context = sys.argv[4]
|
||||||
self.secret = sys.argv[3]
|
|
||||||
self.context = sys.argv[4]
|
print('Context: '+ context)
|
||||||
print('ClientId: ' + self.clientId)
|
|
||||||
print('Secret: ' + self.secret)
|
|
||||||
print('Context: '+ self.context)
|
|
||||||
|
|
||||||
self.context=urllib.parse.quote(self.context, safe='')
|
context=urllib.parse.quote(context, safe='')
|
||||||
print('Context safe: '+ self.context)
|
print('Context safe: '+ context)
|
||||||
|
|
||||||
|
accessToken=self.getAccessToken()
|
||||||
loginheaders = { 'Accept' : 'application/json', 'Content-Type' : 'application/x-www-form-urlencoded'}
|
|
||||||
logindata = { 'grant_type' : 'client_credentials', 'client_id' : self.clientId, 'client_secret' : self.secret}
|
|
||||||
|
|
||||||
# login with offline_token
|
|
||||||
resp1 = requests.post(self.iamURL, data=logindata, headers=loginheaders)
|
|
||||||
jwt1 = resp1.json()
|
|
||||||
print("Resp1: ",jwt1)
|
|
||||||
|
|
||||||
umaheaders = { "Accept" : "application/json", "Content-Type" : "application/x-www-form-urlencoded"}
|
umaheaders = { "Accept" : "application/json", "Content-Type" : "application/x-www-form-urlencoded"}
|
||||||
umadata = { 'grant_type' : 'urn:ietf:params:oauth:grant-type:uma-ticket', 'audience' : self.context}
|
umadata = { 'grant_type' : 'urn:ietf:params:oauth:grant-type:uma-ticket', 'audience' : context}
|
||||||
|
|
||||||
#get UMA token for context
|
# Get UMA token for context
|
||||||
umaheaders["Authorization"] = "Bearer " + jwt1["access_token"]
|
umaheaders["Authorization"] = "Bearer " + accessToken
|
||||||
resp2 = requests.post(self.iamURL, data=umadata, headers=umaheaders)
|
resp2 = requests.post(self.iamURL, data=umadata, headers=umaheaders)
|
||||||
jwt2 = resp2.json()
|
jwt2 = resp2.json()
|
||||||
print("Resp2: ",jwt2)
|
print("Resp2: ",jwt2)
|
||||||
|
|
Loading…
Reference in New Issue