Skip to content

Instantly share code, notes, and snippets.

@maxux
Created February 1, 2019 12:54
Show Gist options
  • Save maxux/575816bc629ed89a234137889ffb90ae to your computer and use it in GitHub Desktop.
Save maxux/575816bc629ed89a234137889ffb90ae to your computer and use it in GitHub Desktop.
import argparse
import requests
def generatetoken(clientid, clientsecret, organization=None, validity=None):
params = {
'grant_type': 'client_credentials',
'client_id': clientid,
'client_secret': clientsecret,
'response_type': 'id_token',
'scope': 'offline_access'
}
if validity:
params['validity'] = validity
if organization:
params['scope'] = 'user:memberof:{},offline_access'.format(organization)
url = 'https://itsyou.online/v1/oauth/access_token'
resp = requests.post(url, params=params)
resp.raise_for_status()
return resp.content.decode('utf8')
if __name__ == '__main__':
clientid = "XXXXX"
clientsecret = "XXXXX"
parser = argparse.ArgumentParser(description='jwt tokenizer')
parser.add_argument('--organization', type=str, help='organization', required=True)
parser.add_argument('--validity', type=str, help='validity time')
args = parser.parse_args()
token = generatetoken(clientid, clientsecret, args.organization, args.validity)
print(token)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment