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

Azure AD: "Record does not exist" on subsequent logins #206

Open
pehbehbeh opened this issue Feb 12, 2021 · 6 comments
Open

Azure AD: "Record does not exist" on subsequent logins #206

pehbehbeh opened this issue Feb 12, 2021 · 6 comments

Comments

@pehbehbeh
Copy link

We just setup Azure AD. The first login / registration works like a charm. But when we logout and login again, we get the following error:

Request: POST /auth/azure/callback
** (exit) an exception was raised:
    ** (RuntimeError) Record does not exist: %MyApp.Accounts.UserIdentity{__meta__: #Ecto.Schema.Metadata<:loaded, "user_identities">, id: "xxx-xxx-xxx-xxx-xxx", inserted_at: ~N[2021-02-12 12:49:00], provider: "azure", uid: "x-xxx-xxx", updated_at: ~N[2021-02-12 12:49:00], user: #Ecto.Association.NotLoaded<association :user is not loaded>, user_id: "xxx-xxx-xxx-xx-xxx"}
        (pow 1.0.22) lib/pow/ecto/context.ex:219: Pow.Ecto.Context.reload_after_write/2
        (pow_assent 0.4.10) lib/pow_assent/ecto/user_identities/context.ex:154: PowAssent.Ecto.UserIdentities.Context.upsert/3
        (pow_assent 0.4.10) lib/pow_assent/plug.ex:315: PowAssent.Plug.upsert_identity/2
        (pow_assent 0.4.10) lib/pow_assent/plug.ex:149: PowAssent.Plug.maybe_upsert_user_identity/1
        (pow_assent 0.4.10) lib/pow_assent/plug.ex:100: PowAssent.Plug.callback_upsert/4
        (pow 1.0.22) lib/pow/phoenix/controllers/controller.ex:77: Pow.Phoenix.Controller.action/3
        (pow_assent 0.4.10) lib/pow_assent/phoenix/controllers/authorization_controller.ex:1: PowAssent.Phoenix.AuthorizationController.action/2
        (pow_assent 0.4.10) lib/pow_assent/phoenix/controllers/authorization_controller.ex:1: PowAssent.Phoenix.AuthorizationController.phoenix_controller_pipeline/2

The record for the user_identity (and the user) definitely exists in the database. Do you have any idea how to solve this problem?

@danschultzer
Copy link
Collaborator

Can you verify that the :id printed does match with an existing record? Does this happen every time you log in? The reload logic just pulls the primary key(s) for the struct and then runs a Repo.get_by call (though I plan to remove these calls).

@RodolfoSilva
Copy link

@danschultzer I've the same issue when I try use a Custom ID generator, like: Exnowflake

I can register the user with the GitHub provider. But I can't log in after the session expires:

image

image

I thought it was related to belongs_to. But it seems not.

https://elixirforum.com/t/custom-useridentity-belongs-to-type/37530

@pehbehbeh
Copy link
Author

Can you verify that the :id printed does match with an existing record?

Yes.

Does this happen every time you log in?

Also yes.

  • Maybe it is related to binary id?
  • Maybe it is because User and UserIdentites are in the same context MyApp.Accounts?

Anything else I can do?

@RodolfoSilva
Copy link

@pehbehbeh try to use the master branch of pow. This worked for me.

@pehbehbeh
Copy link
Author

@pehbehbeh try to use the master branch of pow. This worked for me.

The master branch works for me. Thanks!

@joshuataylor
Copy link

joshuataylor commented Feb 27, 2021

I also get this for a custom integration, looks like it's from pow-auth/pow@4b3433b

Can we get a release for this? Happy using master until then. Thanks!

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

4 participants