pow_assent icon indicating copy to clipboard operation
pow_assent copied to clipboard

MyAppWeb.PowAssent.RegistrationView.render/2 is undefined

Open MMore opened this issue 3 years ago • 6 comments

Hi,

after I've added PowInvitation and trying to use PowAssent for logging in via Google as an invited user I get the following issue. The provider link included the invitation_token as query param.:

[info] Sent 500 in 93ms
[error] #PID<0.1853.0> running MyAppWeb.Endpoint (connection #PID<0.1834.0>, stream id 4) terminated
Server: localhost:4000 (http)
Request: GET /auth/google/add-user-id
** (exit) an exception was raised:
    ** (UndefinedFunctionError) function MyAppWeb.PowAssent.RegistrationView.render/2 is undefined (module MyAppWeb.PowAssent.RegistrationView is not available)
        MyAppWeb.PowAssent.RegistrationView.render("add_user_id.html", %{action: "/auth/google/create", changeset: #Ecto.Changeset<action: :insert, changes: %{email: "[email protected]", email_confirmed_at: ~U[2021-07-02 09:26:03Z], is_admin: true, staff: #Ecto.Changeset<action: :insert, changes: %{first_name: "Mathias", last_name: "N"}, errors: [], data: #MyApp.Staffs.Staff<>, valid?: true>, user_identities: [#Ecto.Changeset<action: :insert, changes: %{provider: "google", uid: "114572126839001341679"}, errors: [], data: #MyApp.Users.UserIdentity<>, valid?: true>]}, errors: [email: {"has already been taken", [constraint: :unique, constraint_name: "users_email_index"]}], data: #MyApp.Users.User<>, valid?: false>, conn: %Plug.Conn{adapter: {Plug.Cowboy.Conn, :...}, assigns: %{action: "/auth/google/create", changeset: #Ecto.Changeset<action: :insert, changes: %{email: "[email protected]", email_confirmed_at: ~U[2021-07-02 09:26:03Z], is_admin: true, staff: #Ecto.Changeset<action: :insert, changes: %{first_name: "Mathias", last_name: "N"}, errors: [], data: #MyApp.Staffs.Staff<>, valid?: true>, user_identities: [#Ecto.Changeset<action: :insert, changes: %{provider: "google", uid: "114572126839001341679"}, errors: [], data: #MyApp.Users.UserIdentity<>, valid?: true>]}, errors: [email: {"has already been taken", [constraint: :unique, constraint_name: "users_email_index"]}], data: #MyApp.Users.User<>, valid?: false>, current_org_id: 1, current_user: nil, layout: {MyAppWeb.LayoutView, "app.html"}, raw_current_tenant: 1}, before_send: [#Function<2.24879655/1 in PowAssent.Plug.init_session/1>, #Function<0.106587690/1 in Plug.CSRFProtection.call/2>, #Function<2.111539819/1 in Phoenix.Controller.fetch_flash/2>, #Function<2.120516169/1 in Pow.Plug.Session.call/2>, #Function<0.123471702/1 in Plug.Session.before_send/2>, #Function<0.11227428/1 in Plug.Telemetry.call/2>, #Function<1.428755/1 in Phoenix.LiveReloader.before_send_inject_reloader/3>], body_params: %{}, cookies: %{"_my_app_key" => "SFMyNTY.g3QAAAACbQAAAAtfY3NyZl90b2tlbm0AAAAYU2hSVEF1Nm1SbzdEWklJblJ3SnU2T00xbQAAAAZvcmdfaWRhAQ.-RLWYthzbqzi4CS3tSZ6nTxp85porUsP-kYUylQSpJM"}, halted: false, host: "localhost", method: "GET", owner: #PID<0.1853.0>, params: %{"provider" => "google"}, path_info: ["auth", "google", "add-user-id"], path_params: %{"provider" => "google"}, port: 4000, private: %{MyAppWeb.Router => {[], %{MyAppWeb.Plugs.RootRedirector => []}}, :phoenix_action => :add_user_id, :phoenix_controller => PowAssent.Phoenix.RegistrationController, :phoenix_endpoint => MyAppWeb.Endpoint, :phoenix_flash => %{}, :phoenix_format => "html", :phoenix_layout => {MyAppWeb.LayoutView, :app}, :phoenix_request_logger => {"request_logger", "request_logger"}, :phoenix_root_layout => {MyAppWeb.LayoutView, :login}, :phoenix_router => MyAppWeb.Router, :phoenix_template => "add_user_id.html", :phoenix_view => MyAppWeb.PowAssent.RegistrationView, :plug_session => %{"_csrf_token" => "ShRTAu6mRo7DZIInRwJu6OM1", "org_id" => 1}, :plug_session_fetch => :done, :pow_assent_callback_params => %{user: %{"email" => "[email protected]", "email_verified" => true, "family_name" => "N", "given_name" => "Mathias", "locale" => "de", "name" => "Mathias N", "picture" => "https://lh3.googleusercontent.com/a-/stripped"}, user_identity: %{"provider" => "google", "token" => %{"access_token" => "ya29.a0ARrdaM-Dwo-Zj1XE2i7hrA-MaBSguNX_ce9y4owgwhE-_j0m9VACnX3x0vY96ohu0vchQUEXxCrBlw0OU2lbFo84EJq2i5X3R0Bj57yjA2pTDzGB4Daqk_T5e8e1kwhkACC3jJ3C8D8Uh-T9gSKND6XQtP81tg", "expires_in" => 3599, "id_token" => "eyJhbGciOiJSUzI1NiIsImtpZCI6ImI2ZjhkNTVkYTUzNGVhOTFjYjJjYjAwZTFhZjRlOGUwY2RlY2E5M2QiLCJ0eXAiOiJKV1QifQ.stripped.stripped-9dGtVz93CwrMyGbEUzRy7Q5M7WCy_vkFZLgjsKlxarkc-stripped-r3skmZcqG2nD3zP9x4hayixC_1XOtunwLRKO-4Ems7-TuXi1Ika99IFrS6xiH-Izd15-yVpEoL7CQ", "scope" => "https://www.googleapis.com/auth/userinfo.email https://www.googleapis.com/auth/userinfo.profile openid", "token_type" => "Bearer"}, "uid" => "1111111111111", "userinfo" => %{"email" => "[email protected]", "email_verified" => true, "family_name" => "N", "given_name" => "Mathias", "locale" => "de", "name" => "Mathias N", "picture" => "https://lh3.googleusercontent.com/a-/AOh14Gg9G8fQWNfMxEEsltSfr-stripped", "sub" => "1111111111111"}}}, :pow_assent_session => %{callback_params: %{"google" => %{user: %{"email" => "[email protected]", "email_verified" => true, "family_name" => "N", "given_name" => "Mathias", "locale" => "de", "name" => "Mathias N", "picture" => "https://lh3.googleusercontent.com/a-/AOh14Gg9G8fQWNfMxEEsltSfr-6Z1BTWOb_w-SemPXX2mA=s96-c"}, user_identity: %{"provider" => "google", "token" => %{"access_token" => "ya29.a0ARrdaM-Dwo-Zj1XE2i7hrA-MaBSguNX_ce9y4owgwhE-_j0m9VACnX3x0vY96ohu0vchQUEXxCrBlw0OU2lbFo84EJq2i5X3R0Bj57yjA2pTDzGB4Daqk_T5e8e1kwhkACC3jJ3C8D8Uh-T9gSKND6XQtP81tg", "expires_in" => 3599, "id_token" => "eyJhbGciOiJSUzI1NiIsImtpZCI6ImI2ZjhkNTVkYTUzNGVhOTFjYjJjYjAwZTFhZjRlOGUwY2RlY2E5M2QiLCJ0eXAiOiJKV1QifQ.stripped.jCTMmi2B4Ls9MiFUnSt4UUd4qs5_DNj5do7KA_o5y9tXudDej5iAPvsU1BjZky4p2jqbQDa9OuWbuGdY9fQC61xyXCH9dRPwrqhb1afZdQW2zWbmscbByZdxfw-9dGtVz93CwrMyGbEUzRy7Q5M7WCy_vkFZLgjsKlxarkc-yOLC2lYdvHMNWIpVjrD5FxveLDNVnvJdXSIRj0V3mMbrfun6Rl3zHo28B9BVpvCTPCbmBLihLxNUPPbf2I7Bg2s7KWbcRVDq-r3skmZcqG2nD3zP9x4hayixC_1XOtunwLRKO-4Ems7-TuXi1Ika99IFrS6xiH-Izd15-yVpEoL7CQ", "scope" => "https://www.googleapis.com/auth/userinfo.email https://www.googleapis.com/auth/userinfo.profile openid", "token_type" => "Bearer"}, "uid" => "1111111111111", "userinfo" => %{"email" => "[email protected]", "email_verified" => true, "family_name" => "N", "given_name" => "Mathias", "locale" => "de", "name" => "Mathias N", "picture" => "https://lh3.googleusercontent.com/a-/AOh14Gg9G8fQWNfMxEEsltSfr-stripped=s96-c", "sub" => "1111111111111"}}}}}, :pow_assent_session_info => :write, :pow_config => [mod: Pow.Plug.Session, plug: Pow.Plug.Session, otp_app: :my_app]}, qu (truncated)

For me it looks like it tries to create the user again and can't because it already exists. But it exists because PowInvitation created it. And it can't find an entry in user_identities because the user wasn't created by himself via Login/Registration with Google.

Any ideas?

MMore avatar Jul 02 '21 09:07 MMore

Ok, I've found the problem and would consider that as bug somewhere between pow and pow_assent.

I am using the PowAssent.Phoenix.ViewHelpers.provider_links/1 helper to generate links. A link looks like that: http://localhost:4000/auth/google/new?invitation_token=1c23e23b-bf9e-4024-b496-0f9e814c7f63. It's the token I find in the database. Clicking this link leads to the error mentioned above. But when I change the invitation_token in the link to the signed token I find in the invitation URL which is SFMyNTY.MWMyM2UyM2ItYmY5ZS00MDI0LWI0OTYtMGY5ZTgxNGM3ZjYz.DahUz1bk3HMc9flALHhdNIpSQ1Xv3hXzG9_1Bhaj9Fs in my case. I can successfully login and a record is created in user_identities. Nevertheless I see that invitation_accepted_at isn't set although that's stated in the README of pow_assent.

Can you confirm or do I have a wrong configuration? Thank you.

MMore avatar Jul 02 '21 10:07 MMore

Sounds like you've generated templates for Pow but not for PowAssent? Try run mix pow_assent.phoenix.gen.templates to generate the templates and view files. It tries to render the screen where you input a different user id if it has already been taken or wasn't provided.

danschultzer avatar Jul 05 '21 18:07 danschultzer

Also I've plans to make it possible to link up the existing users with new provider: https://github.com/pow-auth/pow_assent/issues/115

danschultzer avatar Jul 05 '21 18:07 danschultzer

Hey @danschultzer, indeed the mix task generates two files. I've tried again but the problem persists. I checked the documentations again and it says "Otherwise, Pow will raise an error about missing template when the user id field template is shown" which wasn't the case. Moreover I am wondering why the provider link is wrong. The generation of it seems to be independent on the template. Thank you!

MMore avatar Jul 07 '21 08:07 MMore

Is it the same error? If that's the case, then I would check where MODULE.PowAssent.RegistrationView is. MODULE should be the namespace your project uses. I think this might be the issue as well, and that you are using a different web_module in your config than MyAppWeb.

Moreover I am wondering why the provider link is wrong. The generation of it seems to be independent on the template.

Can you share more information on this?

danschultzer avatar Jul 14 '21 15:07 danschultzer

Hi, yes, it's the same error. I don't have customized templates for PowAssent, so I don't have the template files and not files like MODULE.PowAssent.RegistrationView. I only customized templates and views for Pow, PowEmailConfirmation and PowInvitation. In the pow_invitation/invitation/edit.html.eex I've added a PowAssent link using PowAssent.Phoenix.ViewHelpers.authorization_link(@conn, :google). This link uses the same token I see in the database. Is that correct? Because as I said, when I replace that token to the token I have in the invitation URL it works (at least partly, see 1st and 2nd post above).

Moreover I am wondering why the provider link is wrong. The generation of it seems to be independent on the template. Can you share more information on this?

I mean that the generated templates you mentioned above don't have an impact on the provider link generation itself because they are pure functions.

BTW: I replaced my project module name by MyAppWeb only here in the post.

Thanks!

MMore avatar Jul 15 '21 07:07 MMore