This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import httplib2 | |
from apiclient.discovery import build | |
from oauth2client.client import GoogleCredentials | |
scope = 'https://www.googleapis.com/auth/iam https://www.googleapis.com/auth/cloud-platform' | |
os.environ["GOOGLE_APPLICATION_CREDENTIALS"] = "ServiceAccountA_keyFile.json" | |
credentials = GoogleCredentials.get_application_default() | |
if credentials.create_scoped_required(): | |
credentials = credentials.create_scoped(scope) | |
http = credentials.authorize(httplib2.Http()) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"iss": "serviceAccountB_ID", | |
"scope": "scope1 scope2", | |
"aud": "https://accounts.google.com/o/oauth2/token", | |
"exp": expiration_time, | |
"iat": issue_time | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
client_id= 'serviceAccountB_ID' | |
slist = resource.serviceAccounts().signJwt(name='projects/mineral-minutia-820/serviceAccounts/' + client_id, | |
body={'payload': claim }) | |
resp = slist.execute() | |
signed_jwt = resp['signedJwt'] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
url = 'https://accounts.google.com/o/oauth2/token' | |
data = {'grant_type' : 'assertion', | |
'assertion_type' : 'http://oauth.net/grant_type/jwt/1.0/bearer', | |
'assertion' : signed_jwt } | |
headers = {"Content-type": "application/x-www-form-urlencoded"} | |
data = urllib.urlencode(data) | |
req = urllib2.Request(url, data, headers) | |
resp = urllib2.urlopen(req).read() | |
parsed = json.loads(resp) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
curl https://www.googleapis.com/oauth2/v3/tokeninfo?access_token=ya29.ElnUAws0MfV3om_tqQ0ZS3g7-BZ2ZS_uaJUNdPk8TI7hHkPnFb8Kesg67WQwJswTfD1nYTk-tD0MDUf6X3-pKklpicBDZszq16Q7smBZoDemnYcWaYvJ8gjqnw | |
{ | |
"azp": "104943293997971332223", | |
"aud": "104943293997971332223", | |
"scope": "https://www.googleapis.com/auth/userinfo.email", | |
"exp": "1484452560", | |
"expires_in": "3543", | |
"email": "[email protected]", | |
"email_verified": "true", | |
"access_type": "offline" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"iss": "serviceAccountB_ID", | |
"scope": "serviceAccountB_ID", | |
"aud": "https://www.googleapis.com/oauth2/v4/token", | |
"exp": expiration_time, | |
"iat": issue_time | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
client_id= 'serviceAccountB_ID' | |
slist = resource.serviceAccounts().signJwt(name='projects/mineral-minutia-820/serviceAccounts/' + client_id, | |
body={'payload': id_token_claim }) | |
resp = slist.execute() | |
signed_jwt = resp['signedJwt'] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
url = 'https://www.googleapis.com/oauth2/v4/token' | |
data = {'grant_type' : 'urn:ietf:params:oauth:grant-type:jwt-bearer', 'assertion' : signed_jwt } | |
headers = {"Content-type": "application/x-www-form-urlencoded"} | |
data = urllib.urlencode(data) | |
req = urllib2.Request(url, data, headers) | |
resp = urllib2.urlopen(req).read() | |
parsed = json.loads(resp) | |
id_token = parsed.get('id_token') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from oauth2client.client import verify_id_token | |
from oauth2client.crypt import AppIdentityError | |
try: | |
jwt = verify_id_token(id_token, client_id) | |
self.log('\n ID_TOKEN Validation: \n ' + json.dumps(jwt,sort_keys = False, indent = 4) +' \n', logging.INFO) | |
except AppIdentityError, e: | |
self.log('Payload: ' + str(e.read), logging.ERROR) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
audience = 'SystemC' | |
id_scope='scope1 scope2' | |
now = int(time.time()) | |
exptime = now + 3600 | |
id_token_claim =('{"iss":"%s","scope":"%s", "aud":"%s","exp":%s,"iat":%s}') %(client_id,id_scope,audience,exptime,now) | |
slist = resource.serviceAccounts().signJwt(name='projects/mineral-minutia-820/serviceAccounts/' + client_id, | |
body={'payload': id_token_claim }) | |
resp = slist.execute() | |
signed_jwt = resp['signedJwt'] |