Kenny
06/02/2022, 2:00 AMexport function AuthStack({ stack, app }) {
const { bucket } = use(StorageStack);
const { api } = use(ApiStack);
const auth = new Auth(stack, "Auth", {
login: ["email"],
identityPoolFederation: {
google: {
clientId:
"<http://1097663769791-MYGOOGLECLIENTID.apps.googleusercontent.com|1097663769791-MYGOOGLECLIENTID.apps.googleusercontent.com>",
},
},
});
auth.attachPermissionsForAuthUsers([
api,
new iam.PolicyStatement({
actions: ["s3:*"],
effect: iam.Effect.ALLOW,
resources: [
bucket.bucketArn + "/private/${<http://cognito-identity.amazonaws.com:sub|cognito-identity.amazonaws.com:sub>}/*",
],
}),
]);
stack.addOutputs({
Region: app.region,
UserPoolId: auth.userPoolId,
IdentityPoolId: auth.cognitoIdentityPoolId,
UserPoolClientId: auth.userPoolClientId,
});
return { auth };
}
I found one for Facebook on github https://github.com/AnomalyInnovations/serverless-stack-demo-fb-login-client But is it the same for google?Gabriel
06/02/2022, 9:57 AMKenny
06/02/2022, 10:17 AMKenny
06/02/2022, 10:17 AMKenny
06/02/2022, 10:28 AMKenny
06/02/2022, 10:29 AMconst auth = new Auth(stack, "Auth", {
cdk: {
userPoolClient: {
supportedIdentityProviders: [
cognito.UserPoolClientIdentityProvider.GOOGLE,
],
oAuth: {
callbackUrls: [
app.stage === "prod"
? "prodDomainNameUrl"
: "<http://localhost:3000>",
],
logoutUrls: [
app.stage === "prod"
? "prodDomainNameUrl"
: "<http://localhost:3000>",
],
},
},
},
});
Kenny
06/02/2022, 10:29 AMGabriel
06/02/2022, 10:32 AMGabriel
06/02/2022, 10:33 AMsupportedIdentityProviders is an array you can add both providers in the array.
Kenny
06/02/2022, 10:35 AMKenny
06/02/2022, 10:36 AMconst provider = new cognito.UserPoolIdentityProviderGoogle(stack, "Google", {
clientId: process.env.GOOGLE_CLIENT_ID,
clientSecret: process.env.GOOGLE_CLIENT_SECRET,
userPool: auth.cdk.userPool,
scopes: ["profile", "email", "openid"],
attributeMapping: {
email: cognito.ProviderAttribute.GOOGLE_EMAIL,
givenName: cognito.ProviderAttribute.GOOGLE_GIVEN_NAME,
familyName: cognito.ProviderAttribute.GOOGLE_FAMILY_NAME,
profilePicture: cognito.ProviderAttribute.GOOGLE_PICTURE,
},
});
I need to have two providers one for google and one for facebookGabriel
06/02/2022, 10:44 AMKenny
06/02/2022, 10:46 AMKenny
06/02/2022, 11:14 AMKenny
06/02/2022, 11:15 AMconst api = new Api(stack, "Api", {
authorizers: {
userPool: {
type: "user_pool",
cdk: {
authorizer: new apigAuthorizers.HttpUserPoolAuthorizer(
"Authorizer",
auth.cdk.userPool,
{
userPoolClients: [auth.cdk.userPoolClient],
}
),
},
},
},
defaults: {
authorizer: "userPool",
},
routes: {
},
});
Kenny
06/02/2022, 11:15 AMconst api = new Api(stack, "Api", {
//We are creating an API using SST's Api construct.
defaults: {
authorizer: "iam",
function: {
permissions: [table], //We are giving our API permission to access our DynamoDB table
environment: {
TABLE_NAME: table.tableName, //We'll need this to query our table.
STRIPE_SECRET_KEY: process.env.STRIPE_SECRET_KEY,
},
},
},
routes: {
},
});
at the momentKenny
06/02/2022, 11:15 AMKenny
06/02/2022, 11:15 AMKenny
06/02/2022, 11:15 AMKenny
06/02/2022, 11:15 AMKenny
06/02/2022, 11:39 AMauthorizers: {
userPool: {
type: "user_pool",
cdk: {
authorizer: new apigAuthorizers.HttpUserPoolAuthorizer(
"Authorizer",
auth.cdk.userPool,
{
userPoolClients: [auth.cdk.userPoolClient],
}
),
},
},
},
defaults: {
authorizer: "userPool",
function: {
permissions: [table], //We are giving our API permission to access our DynamoDB table
environment: {
TABLE_NAME: table.tableName, //We'll need this to query our table.
STRIPE_SECRET_KEY: process.env.STRIPE_SECRET_KEY,
},
},
},
Gabriel
06/02/2022, 11:40 AMconst auth = new Auth(stack, "Auth", {
cdk: {
userPoolClient: {
supportedIdentityProviders: [
cognito.UserPoolClientIdentityProvider.COGNITO,
cognito.UserPoolClientIdentityProvider.GOOGLE,
cognito.UserPoolClientIdentityProvider.FACEBOOK
]
},
},
});
Kenny
06/02/2022, 11:40 AMKenny
06/02/2022, 11:41 AM