Integration of AWS Cognito with Graphcool.
Note: Under development, use as a starting point...
- The user clicks the 'Login with Facebook' button
- The Facebook UI is loaded and the user logs in and accepts
- The app receives a Facebook Access Token
- The Facebook token is then passed to AWS Cognito
- Cognito returns the security credentials upon verifying the identity
- Using security credentials, the app calls the API with Facebook token to authenticate it with Graphcool
- The lamba executes the mutation
authenticateFacebookUser(facebookToken: String!)
- If no user exists yet that corresponds to the passed
facebookToken
, a newUser
node will be created - In any case, the
authenticateFacebookUser(facebookToken: String!)
mutation returns a valid token for the user - The app can use the token to call Graphcool API.
Facebook setup is clone of facebook-authentication. Follow the guidelines to set up the app.
Download the AWS SDK for Javascript and place it in your root directory.
- Create a Lambda Function
- Select Author from scratch
- Skip adding triggers
- Name the lambda function, use
Node.js 6.10
as Runtime - Create an Environment varible
GRAPHCOOL_API
with your own API - Assign a Role with
AWSLambdaBasicExecutionRole
policy attached to it - Use 10 sec timeout
- Review and Create
- Create a new API
- Add a new resource
- Add POST method with lambda function
- In Method Request tab, use
AWS_IAM
as Authorization - In Integration Request tab, create a simple Body Mapping from 'Method Request Passthrough' template
- Deploy the API
- Download the Javascript SDK for your API
- Create a new Federated Identities pool
- Use Facebook in Authentication Providers and add the Facebook App Id
- Review the permissions and create the pool
Use the Facebook login button to start the authentication process. After getting the token, call to lambda will be executed which will run the mutation:
client.mutate(`{
authenticateFacebookUser(facebookToken: "${payload.token}") {
token
}
}`).then((token) => callback(null, {
statusCode: 200,
token: token,
body: 'success'
}));
You should see that a new user has been created. The returned token can be used to authenticate requests to your Graphcool API as that user. Note that running the mutation again with the same Facebook token will not add a new user.
The token can be tested using the sample app in the test folder.