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

docs(data-classes): Add more cognito code examples #340

Merged
merged 6 commits into from
Mar 15, 2021

Conversation

michaelbrewer
Copy link
Contributor

@michaelbrewer michaelbrewer commented Mar 14, 2021

Issue #, if available:

Description of changes:

Changes:

  • Add property raw_event to access the _data dict
  • Add more code examples for Cognito triggers showing how to set response values.

eg:

from aws_lambda_powertools.utilities.data_classes.cognito_user_pool_event import (
   DefineAuthChallengeTriggerEvent
)

def handler(event: dict, context) -> dict:
   event: DefineAuthChallengeTriggerEvent = DefineAuthChallengeTriggerEvent(event)
   if (
       len(event.request.session) == 1
       and event.request.session[0].challenge_name == "SRP_A"
   ):
       event.response.issue_tokens = False
       event.response.fail_authentication = False
       event.response.challenge_name = "PASSWORD_VERIFIER"
   elif (
       len(event.request.session) == 2
       and event.request.session[1].challenge_name == "PASSWORD_VERIFIER"
       and event.request.session[1].challenge_result
   ):
       event.response.issue_tokens = False
       event.response.fail_authentication = False
       event.response.challenge_name = "CUSTOM_CHALLENGE"
   elif (
       len(event.request.session) == 3
       and event.request.session[2].challenge_name == "CUSTOM_CHALLENGE"
       and event.request.session[2].challenge_result
   ):
       event.response.issue_tokens = True
       event.response.fail_authentication = False
   else:
       event.response.issue_tokens = False
       event.response.fail_authentication = True

   return event.raw_event

Checklist

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@michaelbrewer
Copy link
Contributor Author

@heitorlessa i expanded on the code examples for Cognito triggers to include how to set response values

@heitorlessa heitorlessa added the documentation Improvements or additions to documentation label Mar 15, 2021
@heitorlessa heitorlessa added this to the 1.12.0 milestone Mar 15, 2021
Copy link
Contributor

@heitorlessa heitorlessa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks again @michaelbrewer for this contribution, much appreciated!

Made comments on areas that could have an additional explanation to ease reading, and some ideas for class methods to ease some Cognito challenges.

docs/utilities/data_classes.md Outdated Show resolved Hide resolved
docs/utilities/data_classes.md Outdated Show resolved Hide resolved
docs/utilities/data_classes.md Outdated Show resolved Hide resolved
docs/utilities/data_classes.md Outdated Show resolved Hide resolved
@codecov-io
Copy link

codecov-io commented Mar 15, 2021

Codecov Report

Merging #340 (f01f0b4) into develop (542eb5b) will increase coverage by 0.00%.
The diff coverage is 100.00%.

Impacted file tree graph

@@           Coverage Diff            @@
##           develop     #340   +/-   ##
========================================
  Coverage    99.88%   99.88%           
========================================
  Files           95       95           
  Lines         3526     3529    +3     
  Branches       173      173           
========================================
+ Hits          3522     3525    +3     
  Misses           2        2           
  Partials         2        2           
Impacted Files Coverage Δ
...lambda_powertools/utilities/data_classes/common.py 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 542eb5b...f01f0b4. Read the comment docs.

@heitorlessa
Copy link
Contributor

Thanks a lot for the changes :) merging it!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants