dwyl / auth

🚪 🔐 UX-focussed Turnkey Authentication Solution for Web Apps/APIs (Documented, Tested & Maintained)
https://authdemo.fly.dev
GNU General Public License v2.0
131 stars 9 forks source link

Bug: GitHub Username Not Returned by Auth ... 🤦‍♂️ #248

Closed nelsonic closed 1 year ago

nelsonic commented 1 year ago

As noted by @LuchoTurtle in https://github.com/dwyl/phoenix-chat-example/pull/120#issuecomment-1323509260 his username does not appear when he logs in via Auth.

The GitHub profile.login should be set to the person.username by this line: https://github.com/dwyl/auth/blob/f6a72102fd72f99ba8c42d00083e22c2fdec917a/lib/auth/person.ex#L126

But for some reason it's not appearing when @LuchoTurtle logs in on the Auth Demo App: https://authdemo.fly.dev/people

image

This appears to be the case on the "prod" version of auth too: https://auth.dwyl.com/people/141 So we need to debug this stat! 👨‍💻 🔥

nelsonic commented 1 year ago

This is quite strange. I'm adding dbg/1 statements to the transform_github_profile_data_to_person/1 function to try and get to the bottom of this. 🤞

nelsonic commented 1 year ago

Not using latest version of Elixir on auth so got the following error:

image
#24 2.585 == Compilation error in file lib/auth/person.ex ==
#24 2.585 ** (CompileError) lib/auth/person.ex:124: undefined function dbg/1
#24 2.585     (elixir 1.12.3) src/elixir_locals.erl:114: anonymous fn/3 in :elixir_locals.ensure_no_undefined_local/3
#24 2.585     (stdlib 3.16.1) erl_eval.erl:685: :erl_eval.do_apply/6

Need to go and find a line to update the Dockerfile: https://github.com/dwyl/auth/blob/f6a72102fd72f99ba8c42d00083e22c2fdec917a/Dockerfile#L15

nelsonic commented 1 year ago

Borrowing Dockerfile from: https://github.com/dwyl/phoenix-chat-example/blob/baba16a988f65851c7c0c95ba2c2b31cfdb027e8/Dockerfile

nelsonic commented 1 year ago

@LuchoTurtle This is working for me on my localhost:

image

Please confirm on your side by visiting: https://authdemo.fly.dev/people

image

Where you person.username is displayed in the Username column.

I logged the JWT on returned by auth ( https://authdemo.fly.dev ) and it includes the username now:

%{
      app_id: 2,
      aud: "Joken",
      auth_provider: "github",
      email: "rex@gmail.com",
      exp: 1700745867,
      givenName: "Rex Dangervest",
      iat: 1669208867,
      id: 7,
      iss: "Joken",
      jti: "2sl3h7ncd22cnc3cck12h",
      nbf: 1669208867,
      picture: "https://avatars.githubusercontent.com/u/10835816?v=4",
      roles: "6,6",
      sid: 76,
      status: 1,
      username: "nkamc"
}
LuchoTurtle commented 1 year ago

This works on my side, it shows the username.

But I think there's something up in auth_plug, the username is not present at all. https://github.com/dwyl/phoenix-chat-example/pull/120#issuecomment-1325073845

This issue should be resolved in auth, but not so much in auth_plug 🤔

LuchoTurtle commented 1 year ago

Aaaaah, it works now. I had to Reset API key

Screenshot 2022-11-23 at 13 36 35

So previous registered apps need to refresh so the JWT brings the username.

nelsonic commented 1 year ago

I didn't refresh my API key. But I'm glad that resetting yours worked. There aren't any other Apps using this auth instance so nobody else should see this issue in practice. 👌