Skip to content
Snippets Groups Projects
Commit d2d54224 authored by kosted's avatar kosted
Browse files

add function to get bearer token

parent 275c7b9c
No related branches found
No related tags found
No related merge requests found
......@@ -33,6 +33,7 @@ def display_help():
print('list folder/path List data in a subfolder')
print('delete path/in/S3/file.tiff Delete an existing data on S3')
print('refresh Refresh credentials and password')
print('token email password Return a bearer token')
print('resume Resume last interrupted multipart upload')
sys.exit(2)
......@@ -114,6 +115,23 @@ def generate_token(email, password):
sys.exit(2)
################################
# Generate token and return it #
###############################
def get_token(email, password):
#print("[INFO] Start retrieving token for authent")
#Set the bearer
url = "https://iam."+MAAP_ENV_TYPE.lower()+".esa-maap.org/oxauth/restv1/token"
response = requests.post(url, data={'client_id': CLIENT_ID, 'username': email, 'password': password, "grant_type": "password", "scope": "openid+profile"})
#Convert the string to json to fecth access_token
data = json.loads(response.text)
token = data['access_token']
print (token)
return token
#########################
# Check if file is older#
#########################
......@@ -481,7 +499,7 @@ argv = sys.argv[1:]
result=0
try:
if len(argv) == 0:
display_help()
else:
......@@ -501,6 +519,12 @@ try:
display_help()
else:
delete(argv[1])
elif argv[0] == 'token':
# Delete a data
if len(argv) != 3:
display_help()
else:
get_token(argv[1], argv[2])
elif argv[0] == 'download':
# Download a data
if len(argv) != 3:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment