Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dynamo Cache token validation and expiration #45

Open
buholzer opened this issue Jun 3, 2017 · 0 comments
Open

Dynamo Cache token validation and expiration #45

buholzer opened this issue Jun 3, 2017 · 0 comments

Comments

@buholzer
Copy link

buholzer commented Jun 3, 2017

Thanks so much for implementing the boilerplate, very helpful!

I saw that in the dynamo cache the existence of the token is not checked:

    const newRefreshToken = (data) => {
      const userId = data.Items[0].userId;
      const payload = data.Items[0].payload;

https://github.com/laardee/serverless-authentication-boilerplate/blob/master/authentication/lib/storage/dynamo/dynamoCache.js#L149

Added the following check:

  if (data.Count <= 0) return Promise.reject('Invalid token');

Also it looks like you can use expired tokens, the query does not restrict to expired=false:

      const params = {
        TableName: table,
        ProjectionExpression: '#token, #type, #userId',
        KeyConditionExpression: '#token = :token and #type = :type',
        ExpressionAttributeNames: {
          '#token': 'token',
          '#type': 'type',
          '#userId': 'userId'
        },
        ExpressionAttributeValues: {
          ':token': oldToken,
          ':type': 'REFRESH'
        }
      };

https://github.com/laardee/serverless-authentication-boilerplate/blob/master/authentication/lib/storage/dynamo/dynamoCache.js#L129

Changed params to:

      const params = {
        TableName: table,
        ProjectionExpression: '#token, #type, #userId, #expired',
        KeyConditionExpression: '#token = :token and #type = :type',
        FilterExpression: '#expired = :expired',
        ExpressionAttributeNames: {
          '#token': 'token',
          '#type': 'type',
          '#userId': 'userId',
          '#expired': 'expired'
        },
        ExpressionAttributeValues: {
          ':token': oldToken,
          ':type': 'REFRESH',
          ':expired': false
        }
      };
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant