Skip to content

Instantly share code, notes, and snippets.

@gjyoung1974
Created October 3, 2018 01:52
Show Gist options
  • Save gjyoung1974/1aa9c7ba34268e1398307660e0f7f1e5 to your computer and use it in GitHub Desktop.
Save gjyoung1974/1aa9c7ba34268e1398307660e0f7f1e5 to your computer and use it in GitHub Desktop.
Get Auth and Refresh token from KeyCloak
import requests
import json
import urllib
# encode the form data
login_data = urllib.urlencode({
'client_id': 'owasp-zap-client-id',
'client_secret': '....',
'username': '[email protected]',
'grant_type': 'password',
'password': 'some_password'
})
def auth0_login():
# Post it
login_headers = {'Content-Type': 'application/x-www-form-urlencoded'}
token_response = requests.post('https://auth.example.com/auth/realms/{some-realm}/protocol/openid-connect/token',
headers=login_headers, data=login_data
)
# get some tokens back
return token_response
accesstoken = json.loads(auth0_login().text)['access_token']
refreshtoken = json.loads(auth0_login().text)['refresh_token']
print accesstoken
print ''
print refreshtoken
# print auth0_login().text
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment