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

Support for sign in with local credentials #229

Merged
merged 17 commits into from
Apr 26, 2024
Merged

Support for sign in with local credentials #229

merged 17 commits into from
Apr 26, 2024

Conversation

natalian98
Copy link
Contributor

@natalian98 natalian98 commented Apr 19, 2024

This PR adds support for signing in with local credentials (kratos password method). MFA, recovery and verification will be addressed in future PRs.

Testing

Set up docker env:

docker-compose -f docker-compose.dev.yml up --build --force-recreate --remove-orphans

docker exec <hydra-container> \
  hydra create client \
    --endpoint http://127.0.0.1:4445 \
    --name grafana \
    --grant-type authorization_code,refresh_token \
    --response-type code,id_token \
    --format json \
    --scope openid,offline_access,email \
    --redirect-uri http://localhost:2345/login/generic_oauth

docker run -d --name=grafana -p 2345:2345 --network idp-docker_intranet \
-e "GF_SERVER_HTTP_PORT=2345" \
-e "GF_AUTH_GENERIC_OAUTH_ENABLED=true" \
-e "GF_AUTH_GENERIC_OAUTH_AUTH_ALLOWED_DOMAINS=hydra,localhost" \
-e "GF_AUTH_GENERIC_OAUTH_NAME=Identity Platform" \
-e "GF_AUTH_GENERIC_OAUTH_CLIENT_ID=<client-id>" \
-e "GF_AUTH_GENERIC_OAUTH_CLIENT_SECRET=<client-secret>" \
-e "GF_AUTH_GENERIC_OAUTH_SCOPES=openid offline_access email" \
-e "GF_AUTH_GENERIC_OAUTH_AUTH_URL=http://localhost:4444/oauth2/auth" \
-e "GF_AUTH_GENERIC_OAUTH_TOKEN_URL=http://hydra:4444/oauth2/token" \
-e "GF_AUTH_GENERIC_OAUTH_API_URL=http://hydra:4444/userinfo" \
grafana/grafana

docker exec <kratos-container> kratos import identities /etc/config/kratos/identity.json --endpoint http://127.0.0.1:4434

Run login ui:

make npm-build build

export KRATOS_PUBLIC_URL="http://localhost:4433"
export HYDRA_ADMIN_URL="http://localhost:4445"
export BASE_URL="http://localhost:4455"
export PORT="4455"
export TRACING_ENABLED="false"
export LOG_LEVEL="debug"
export AUTHORIZATION_ENABLED="false"

go run . serve

Go to http://localhost:2345 and sign in with identity platform. It will redirect to login ui and display the option to sign in with local credentials:
image

If incorrect credentials are typed, error will be shown:
image

Logging in with the imported test user (test@example.com / mQ#v9fwHc0@8) logs the user to grafana:
image

I also tested logging with external idp to make sure the changes don't break it.

@natalian98 natalian98 changed the title Local idp login Support for sign in with local credentials Apr 19, 2024
@natalian98 natalian98 marked this pull request as ready for review April 19, 2024 12:00
@natalian98 natalian98 requested a review from a team as a code owner April 19, 2024 12:00
Copy link
Contributor

@nsklikas nsklikas left a comment

Choose a reason for hiding this comment

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

Good job overall. I left some comments, but most of them don't require changes in the current PR. To sum up the changes that I think are needed in this PR:

  • I think we can get rid of the UiErrorMessages struct, we can use kCLient.LoginFlow instead
  • Would it make sense to just propagate the error description that kratos sends us in getUiError instead of creating our own messages? This is part of a larger error handling refactoring we need to do in the login UI, so feel free to disregard it.
  • Could we automatically import the Kratos users when running the docker compose? (perhaps we could add an entrypoint script or run "job" container like we do for the migration?)
  • Add a kratos/service test that tests the service behavior when we get a kratos error response when using the password method, e.g. the user has entered a wrong password

pkg/kratos/service.go Show resolved Hide resolved
docker-compose.dev.yml Show resolved Hide resolved
docker/kratos/identity.json Show resolved Hide resolved
docker/kratos/identity.json Outdated Show resolved Hide resolved
pkg/kratos/service.go Outdated Show resolved Hide resolved
pkg/kratos/service.go Show resolved Hide resolved
pkg/kratos/service.go Outdated Show resolved Hide resolved
pkg/kratos/service.go Show resolved Hide resolved
pkg/kratos/service.go Outdated Show resolved Hide resolved
@natalian98 natalian98 merged commit 678976c into main Apr 26, 2024
6 checks passed
@natalian98 natalian98 deleted the local-idp-login branch April 26, 2024 12:01
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

Successfully merging this pull request may close these issues.

4 participants