I tried 3 different options, the first worked for my scenario:
The first option is to confirm the Google ID token for each call on the lambda side
I always pass id_token as a header on client calls (web and mobile applications).
"allowedHds" - a list of allowed domains.
const oauth = new Auth.OAuth2(CLIENT_ID_WEB, CLIENT_SECRET); oauth.verifyIdToken(token, null, (err, ticket) => { if (err) { return reject(err); } const payload = ticket.getPayload(); const tokenIsOK = payload && payload.aud === CLIENT_ID && new Date(payload.exp * 1000) > new Date() && acceptableISSs.has(payload.iss) && acceptableHds.has(payload.hd) return tokenIsOK ? resolve(payload.hd) : reject(); });
The second option is to confirm the Google Id token on the lambda side
I started this alternative path, but I did not finish, because the first solutions that corresponded to my needs and the steps were close (for this I need a pool of indents):
1) Send id_token to the lambda function and confirm it in the Google API (here you can check the domain using the code above)
2) Call the cognitoidentity.getOpenIdTokenForDeveloperIdentity function on the lambda side using the id_token coming from the browser.
3) On the client, call any of the Cognito or STS functions, such as takeWebIdentity, AssumeRole, using the tokens returned from getOpenIdToken.
function getCognitoToken(id_token) { var param = { IdentityPoolId: 'us-east-1:f7b3d55f-6b63-4097-be8f-3dc22ddec1a4', Logins: { 'accounts.google.com': id_token } } return check_company(id_token).then(function (valid) { return cognitoidentity.getOpenIdTokenForDeveloperIdentity(param).promise() })
I could not finish the third step. You need to use the tokens obtained in the second step without revealing the identifier pool identifier. If you do this and make sure that the role cannot contain the identifier pool identifiers, it will work as intended and will be safe.
Third Option - SAML Provider
You can create a SAML provider and use SAML statements to validate a user's domain.
http://docs.aws.amazon.com/IAM/latest/UserGuide/id_roles_providers_create_saml_assertions.html
I tried unsuccessfully to do this.
PS: Google Admin allows you to create private applications, limiting your corporate domains, but it works only for mobile phones, as far as I know.
https://support.google.com/a/answer/2494992?hl=en
Hope this helps someone!