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

Get login (no social provider) working in turnkey #274

Closed
23 of 33 tasks
douglasnaphas opened this issue Feb 7, 2021 · 11 comments
Closed
23 of 33 tasks

Get login (no social provider) working in turnkey #274

douglasnaphas opened this issue Feb 7, 2021 · 11 comments

Comments

@douglasnaphas
Copy link
Owner

douglasnaphas commented Feb 7, 2021

TODO

  • Update Puppeteer.
  • Add a Cognito User Pool.
  • Create a bucket in the stack to hold the Cognito user pool client secret (the client secret bucket).
  • Add the user pool id to stack output.
  • Get the user pool id in save-client-secret.sh
  • Get the client secret in save-client-secret.sh
  • Try using Dynamo with DAX instead, because I'm not sure how to get the S3 content, as opposed to the file, with the S3 SDK, although I do this for the scripts in mljsapi... Deferring, going to try with S3
  • Save the client secret to the client secret bucket after deploying the stack.
  • Have the backend take in the client secret bucket name as an env var.
  • Update itest to have a player click log in.
  • Find out how to programmatically get the hosted UI URL. Maybe output it? Try with the AWS CLI. It will need to get fed to the fronted, and to itest.
  • Do some assertions about the location, specifically asserting that it's what's expected given the Cognito login URL.
  • See the above test fail in CI.
  • Add a prettier config to package.json at the madliberation level. Read through the options and figure out which I want. Issue Harmonize prettier settings #277 created for this.
  • Get the test working, so that clicking the login button takes you to the right URL.
    • Hard-code the URL.
    • Watch it pass in dev.
    • Merge and watch it fail in higher envs. Does failing in test end the build, or does it still attempt prod? it should not attempt prod if test fails, good time to check this. The build did not proceed after the test env integration test step failed, as desired.
    • Save/retrieve the Cognito domain with SSM param store. Deferring, not sure if this would work given the build steps.
    • Make frontend/ require an env var for the build to happen, via checking in a build script. This might need to be reconsidered, since I'm not sure if REACT_APP_ vars are read at build or run time. Update: they're read at build time, so they go into the bundle. Still not sure if this is the right approach, as opposed to receiving a redirect from a backend endpoint.
    • Make backend app.test.js testing that app returns 301 from /login, using Jest.
    • Make the backend /login test look for different outcomes based on the important env vars.
    • Feed the Cognito-related env vars to backend in the CDK webapp stack.
    • Get the login test passing with a redirect returned from /prod/login, which will be linked from the login button.
      • Dev
      • Test
      • Prod
  • Pull the IDP URL from Configs, isolating process.env accesses there.
  • Use API calls to create and confirm a user for testing, in the build. Better yet, with the SDK in the itest script.
  • Use test user in itest.
  • Remove the user after the itests.
  • Only check for nickname from the JWTs in getUserInfo.
  • Get /get-cookies working.
@douglasnaphas
Copy link
Owner Author

douglasnaphas commented Feb 9, 2021

Cogito legacy prod URL

https://madliberationfederated.auth.us-east-1.amazoncognito.com/login?response_type=code&client_id=25h54vd0cundt7iaeon1rn8a02&redirect_uri=https://api.passover.lol/get-cookies

Domain name: stackname to lower. Actually this should maybe be something with the User Pool ID, because otherwise the names will conflict between test and prod. This is done as of f9465f436e, using a hash of stackname plus the account number.

Redirect uri as CloudFront member to Cognito via constructor. Done in dev.

Client secret as env var with addEnvironment call after user pool creation in lib/MLStack.ts. Except...you can't get the client secret at CDK compile time. Maybe S3?

Likewise for client id and whatever else backend needs to know about user pool

Client id to front end via param store or front end deploy script can get stack output

Likewise for cognito link, or construct it

douglasnaphas added a commit that referenced this issue Feb 9, 2021
gh-274

I got an error:

clientCredentials OAuth flow cannot be selected along with codeGrant or
implicitGrant.

I don't think I use Client Credentials when I exchange the authorization
code for tokens. It doesn't look like the passover.lol User Pool has
Client Credentials enabled.
douglasnaphas added a commit that referenced this issue Feb 9, 2021
gh-274

For the Cognito Hosted UI. This is so I don't get naming conflicts on
the prefix between, for example, test and prod.
douglasnaphas added a commit that referenced this issue Feb 9, 2021
gh-274

The synth command revealed that the Cognito Domain had a CloudFormation
Ref to the UserPool id.
douglasnaphas added a commit that referenced this issue Feb 9, 2021
gh-274

This relates to finding a name for the Cognito domain.

It has to be globally unique.

A recent run, which attempted to use the User Pool id (not known until
deployment, complicating matters), failed with the error:

The domain name contains an invalid character. Domain names can only
contain lower-case letters, numbers, and hyphens. Please enter a
different name that follows this format:
^[a-z0-9](?:[a-z0-9\-]{0,61}[a-z0-9])?$

Looks like we get about 62 characters for the domain prefix, so I might
want to add a fixed-size hashing feature to @cdk-turnkey/stackname to
ensure we stay in that limit.
douglasnaphas added a commit that referenced this issue Feb 9, 2021
gh-274

This issue has some discussion of why I want this, and why hashing is a
nice technique for naming AWS resources like the Cognito User Pool
domain name prefix: cdk-turnkey/stackname#1.
douglasnaphas added a commit that referenced this issue Feb 9, 2021
gh-274

This is based on the workaround for the exact problem described here:

aws/aws-cdk#10062

Basically I got the error "User pool already has a domain configured."
when I tried to rename the User Pool Domain.

So here I'm deleting the user pool domain so I can re-deploy it with a
new name. It's the workaround described as a "2-stage deploy" in the
issue comments.
douglasnaphas added a commit that referenced this issue Feb 9, 2021
gh-274

This is to complete the 2-step deploy described here:

aws/aws-cdk#10062 (comment)

I'm renaming the Cognito User Pool Domain with a fixed-size string with
acceptable letters for a Domain prefix, and that varies based on the
repo namespace, repo name, branch, and account.
@douglasnaphas
Copy link
Owner Author

Hosted UI is available in dev at the URL from my previous comment.

Screen Shot 2021-02-09 at 10 19 57 AM

douglasnaphas added a commit that referenced this issue Feb 11, 2021
gh-274

This is step towards saving the client secret somewhere that the backend
can get it after deployment.
douglasnaphas added a commit that referenced this issue Feb 11, 2021
gh-274

This tries to validate the syntax for saving the user pool client secret
to S3, where backend will be able to find it. It saves non-secret data
from the Cognito user pool client, but if the data winds up in the
bucket without being printed in Actions, I'll change it so that it saves
the actual secret.
douglasnaphas added a commit that referenced this issue Feb 13, 2021
douglasnaphas added a commit to douglasnaphas/madliberation-itest that referenced this issue Feb 13, 2021
douglasnaphas added a commit to douglasnaphas/madliberationjs that referenced this issue Feb 14, 2021
douglasnaphas/madliberation#274

This is a first step towards making the Cognito domain vary correctly by
environment.
douglasnaphas added a commit that referenced this issue Feb 14, 2021
douglasnaphas added a commit that referenced this issue Feb 14, 2021
gh-274

This should fail, as the required env var is not set.
douglasnaphas added a commit to douglasnaphas/madliberationjs that referenced this issue Feb 14, 2021
douglasnaphas/madliberation#274

This is the only way I could find for frontend to make sure that it has
the link to its Cognito User Pool domain.
douglasnaphas added a commit to douglasnaphas/madliberationjs that referenced this issue Feb 14, 2021
douglasnaphas added a commit to douglasnaphas/madliberationjs that referenced this issue Feb 14, 2021
douglasnaphas/madliberation#274

The backend will next need to return from /prod/login with a redirect to
the Cognito hosted UI URL.
douglasnaphas added a commit to douglasnaphas/mljsapi that referenced this issue Feb 14, 2021
douglasnaphas/madliberation#274

This needs to turn in to determining and sending back via Location the
Cognito Hosted UI URL.
douglasnaphas added a commit that referenced this issue Feb 14, 2021
gh-274

This was part of a currently unfavored effort to communicate the Cognito
hosted UI URL to the frontend by injecting an environment variable at
build time. I am going to pursue instead the strategy of having the Log
In link on the home page link to /prod/login, and having backend's
/prod/login return a redirect to the Cognito hosted UI URL. I'm
committing scripts/build-frontend.sh, which will not be used in the
preferred setup, so I have a record of it.
douglasnaphas added a commit that referenced this issue Feb 14, 2021
gh-274

See the previous commit message, the one where I added the file I'm
removing here, for rationale. This is part of an attempt to make it so
that I don't have to build the frontend static files for each env.
douglasnaphas added a commit that referenced this issue Feb 14, 2021
gh-274

I don't have an API for this app, I have a backend. Nobody but my
frontend calls it.
douglasnaphas added a commit that referenced this issue Feb 14, 2021
gh-274

Note the env-specific Actions steps as being for the dev env.
douglasnaphas added a commit to douglasnaphas/madliberation-itest that referenced this issue Feb 19, 2021
douglasnaphas/madliberation#274

This sets up the integration test to create a user (in setup, via the
SDK), then log in as the user. This validates that the user pool is
usable.

The last implemented piece is trying to join the seder as Player 2. This
should fail, because /get-cookies is not set up under turnkey yet.
douglasnaphas added a commit that referenced this issue Feb 19, 2021
gh-274

See the commit message for the itest commits brought in here.

This expands the itest script to log in and change the password for
Player 2.

It should fail when it tries to join the seder, because that is not yet
implemented under turnkey.
douglasnaphas added a commit to douglasnaphas/mljsapi that referenced this issue Feb 19, 2021
douglasnaphas added a commit that referenced this issue Feb 19, 2021
gh-274

This is so the backend can run in multiple environments (accounts, Git
branches).
douglasnaphas added a commit that referenced this issue Feb 19, 2021
gh-274

Taken from the workaround in the issue description here:
aws/aws-cdk#7112.

My error noted here:
aws/aws-cdk#7112 (comment)
douglasnaphas added a commit that referenced this issue Feb 19, 2021
@douglasnaphas
Copy link
Owner Author

I'm checking in the backend that specific claims are available, when this isn't necessary.

Screen Shot 2021-02-19 at 6 48 54 AM

@douglasnaphas
Copy link
Owner Author

Users should be able to sign up with just a Mad Liberation username/password, but they should be prompted for an email on signup.

I need to check and see what user info is available in different scenarios (social login, no email provided, etc), because the frontend needs to say "Logged in as X."

douglasnaphas added a commit that referenced this issue Feb 21, 2021
gh-274

Temporarily comment-out the itest step against the test env. This allows
test-breaking changes to flow through to prod, deleting the user pool so
it can be re-created with changes to attributes.
douglasnaphas added a commit that referenced this issue Feb 21, 2021
@douglasnaphas
Copy link
Owner Author

Here's a good piece of progress. It's redirecting to /, as desired.

Screen Shot 2021-02-21 at 10 09 40 AM

douglasnaphas added a commit to douglasnaphas/mljsapi that referenced this issue Feb 21, 2021
douglasnaphas added a commit to douglasnaphas/madliberationjs that referenced this issue Feb 21, 2021
douglasnaphas/madliberation#274

Everything (frontend and backend) runs behind the same host in the
Turnkey setup, thanks to CloudFront.
douglasnaphas added a commit to douglasnaphas/madliberationjs that referenced this issue Feb 21, 2021
douglasnaphas/madliberation#274

It needs to be relative to the base location /prod/.
douglasnaphas added a commit that referenced this issue Feb 21, 2021
@douglasnaphas
Copy link
Owner Author

Working in manual testing, failing in CI.

Screen Shot 2021-02-21 at 11 34 33 AM

@douglasnaphas
Copy link
Owner Author

It's failing in CI because I forgot to supply a now-required nickname for the test user.

Screen Shot 2021-02-21 at 11 57 48 AM

douglasnaphas added a commit to douglasnaphas/madliberation-itest that referenced this issue Feb 21, 2021
douglasnaphas/madliberation#274

Nickname is required now, because the frontend needs it so it can say
"Logged in as <NICKNAME>."
douglasnaphas added a commit that referenced this issue Feb 21, 2021
gh-274

They will be re-created in the branch for gh-274 with settings that
cannot be changed in a deployed user pool
douglasnaphas added a commit that referenced this issue Feb 21, 2021
gh-274

This is in preparation for bringing in changes from the current head of
the 274-basic-login branch, 2b6cc2d, where login is working.
@douglasnaphas
Copy link
Owner Author

Works in prod, closing.

Screen Shot 2021-02-21 at 2 34 43 PM

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