Chapter 23 Github Authentication

Hey folks,

I implemented the google login fine and when I was implementing the Github login, the first time I tried to login with Github I was sent to the Github login screen, entered my creds and was sent to the authorization page, clicked the button to authorize the TIL app and was thrown an error there.

I logged out and logged in with google again, and was logged in correctly. Then I logged out of the TIL app and tried to login with Github again. I was immediately thrown an error and the url was http://localhost:8080/oauth/github?code=07130fd5465dfbcfec22
Is this possible a token issue or session issue? The second login with google brings me right into the home screen, but subsequent attempts to login with Github seems to throw errors immediately.

Iā€™m using the Chrome browser in incognito mode because safari seems to force connections to localhost through https for some reason.

The TIL Server app seems to also be throwing multiple errors after the GitHub login attempts

**Server starting on http://localhost:8080**

**[ ERROR ] Abort.404: Not Found (ApplicationResponder.swift:50)**

**2019-04-11 15:59:19.362871-0700 Run[10022:141943] SecTaskLoadEntitlements failed error=22 cs_flags=20, pid=10022**

**2019-04-11 15:59:19.362960-0700 Run[10022:141943] SecTaskCopyDebugDescription: Run[10022]/0#-1 LF=0**

**[ ERROR ] Abort.404: Not Found (ApplicationResponder.swift:50)**

**[ ERROR ] Abort.404: Not Found (ApplicationResponder.swift:50)**

**2019-04-11 16:01:20.220707-0700 Run[10022:143790] [BoringSSL] nw_protocol_boringssl_get_output_frames(1301) [C1.1:2][0x101d24090] get output frames failed, state 8196**

**2019-04-11 16:01:20.220745-0700 Run[10022:143790] [BoringSSL] nw_protocol_boringssl_get_output_frames(1301) [C1.1:2][0x101d24090] get output frames failed, state 8196**

**2019-04-11 16:01:20.220880-0700 Run[10022:143790] TIC Read Status [1:0x0]: 1:57**

**2019-04-11 16:01:20.220889-0700 Run[10022:143790] TIC Read Status [1:0x0]: 1:57**

**2019-04-11 16:01:42.432617-0700 Run[10022:144091] [BoringSSL] nw_protocol_boringssl_get_output_frames(1301) [C2.1:2][0x104d2ec80] get output frames failed, state 8196**

**2019-04-11 16:01:42.432655-0700 Run[10022:144091] [BoringSSL] nw_protocol_boringssl_get_output_frames(1301) [C2.1:2][0x104d2ec80] get output frames failed, state 8196**

**2019-04-11 16:01:42.432784-0700 Run[10022:144091] TIC Read Status [2:0x0]: 1:57**

**2019-04-11 16:01:42.432793-0700 Run[10022:144091] TIC Read Status [2:0x0]: 1:57**

the actual error seems to be

**[ ERROR ] DecodingError.valueNotFound: Value of type 'String' required for key 'name'. (ErrorMiddleware.swift:26)**

Is the response from Github not in the manner we are expecting here? or do I need to do some update on Imperial? Where can I check what response to expect from the GitHub api?

Itā€™s possible itā€™s a bug in Imperial because youā€™re already logged in, Iā€™ll take a look. But definitely make sure youā€™re on the latest versions of everything with swift package update

Have you had any luck figuring this one out?

I am getting the same error.

And thatā€™s starting with:
ā€¢ swift package update
ā€¢ final version of the source files in 23-github-authentication
ā€¢ adding Google and GitHub environment variables in Xcode

When I click on the Github buttonā€¦

Safari (v12.1.2) displays:

{"error":true,"reason":"Value of type 'String' required for key 'name'."}

Xcode (v10.3) logs:

[ ERROR ] Abort.404: Not Found (ApplicationResponder.swift:50)

2019-09-07 11:53:43.179453-0400 Run[71258:3233308] SecTaskLoadEntitlements failed error=22 cs_flags=20, pid=71258

2019-09-07 11:53:43.179547-0400 Run[71258:3233308] SecTaskCopyDebugDescription: Run[71258]/0#-1 LF=0

[ ERROR ] DecodingError.valueNotFound: Value of type 'String' required for key 'name'. (ErrorMiddleware.swift:26)

[ ERROR ] Abort.404: Not Found (ApplicationResponder.swift:50)

When I click on the Google buttonā€¦

Safari (v12.1.2) displays:

{"error":true,"reason":"null value in column \"email\" violates not-null constraint"}

Xcode (v10.3) displays:

[ ERROR ] Abort.404: Not Found (ApplicationResponder.swift:50)

2019-09-07 13:24:17.347930-0400 Run[84359:3429739] SecTaskLoadEntitlements failed error=22 cs_flags=20, pid=84359

2019-09-07 13:24:17.348022-0400 Run[84359:3429739] SecTaskCopyDebugDescription: Run[84359]/0#-1 LF=0

[ ERROR ] PostgreSQLError.server.error.ExecConstraints: null value in column "email" violates not-null constraint (ErrorMiddleware.swift:26)

[ DEBUG ] Possible causes for PostgreSQLError.server.error.ExecConstraints: Failing row contains (efb3612c-7f91-406c-9623-4caf20d098f0, B G, yousnite@gmail.com, 33C08F20-BFFD-4CCD-A89E-FA0D4BAAC095, null, null, null, null). (ErrorMiddleware.swift:26)

[ ERROR ] Abort.404: Not Found (ApplicationResponder.swift:50)

Hmm that would suggest that the POST request youā€™re sending (or Google/GH is sending) doesnā€™t match up with what the code is expecting. Do you know what line of code itā€™s failing on?

i got the same error when follow vapor book raywenderlich(server side swift with vapor) at chapter 2: hello world. After type ā€œvapor runā€ in terminal as instruction, i got <[ ERROR ] Abort.404: Not Found (ApplicationResponder.swift:50)> so how can i iron it out, please help me, thank you!

@vudat81299 what request gives you that error or is it in the browser? If itā€™s in the browser and everything else works you can just ignore it, itā€™s the browser asking for a favicon, which doesnā€™t exist in the app

I am experiencing this same issue. I cannot ignore it though, as it prevents logging in using GitHub.

Here are the errorā€™s displayed in the console:

[ ERROR ] Abort.404: GET /favicon.ico Not Found (ApplicationResponder.swift:50)

[ ERROR ] DecodingError.valueNotFound: GET /oauth/github?code=1fab7ea3deb0cf2bf59e Value of type ā€˜Stringā€™ required for key ā€˜nameā€™. (ErrorMiddleware.swift:26)

[ ERROR ] DecodingError.valueNotFound: GET /oauth/github?code=e6b78a05fe7c05ca99cd Value of type ā€˜Stringā€™ required for key ā€˜nameā€™. (ErrorMiddleware.swift:26)

[ ERROR ] DecodingError.valueNotFound: GET /oauth/github?code=393eedcc09cdfc80d046 Value of type ā€˜Stringā€™ required for key ā€˜nameā€™. (ErrorMiddleware.swift:26)

Also note, this was the result when I built and ran the starter from Chapter 24 (I had to manually configure the environment variables for Google and GitHub). Google authentication works fine, but GitHub does not.

A couple more points:

  • This issue occurs using both Safari and Chrome.
  • This issue occurs with Safari, even when favicons are disabled.

The 404 for the favicon is a red herring here. The other errors are more pressing. Do you know where in Imperial it throws that error from?

Is there a way to determine what is throwing the error?

I just retried this and this time GitHub sent me an email containing the following:

Previously, a third-party OAuth application (Vapor TIL) did not have any scopes. It was recently granted an additional scope (user:email).

I think this happened because I continued on to the next chapters.

@gili basically breakpoint in the code, step through until it throws an error

Googles oAuth works fine, but Iā€™m getting the same error on GitHub OAuth. The error appears on this breakpoint. Any help? I canā€™t go further with the book. I need to figure out this otherwise it makes me go crazy. :smiley: Screenshot 2020-03-05 at 14.17.01

So, as I said I went crazy and this helped me to figure out.

I set up GitHubUserInfo structā€™s value name to optional. Because guess what? This value can be nil! That was causing the problem for me.

Screenshot 2020-03-05 at 15.14.40

The second implemented nil coalescing to on userInfo.name (because now itā€™s optional):

Screenshot 2020-03-05 at 15.21.21

Now it works. I think this would be a great update for the book.

Are you requesting the name scope with GitHub?

Great Catch!! I ran into this as well because by Githhub profile that I used only has a user name and not a name. Your fix worked for me! Thanks!