goth icon indicating copy to clipboard operation
goth copied to clipboard

Apple auth with scopes not working correct

Open pasifus opened this issue 3 years ago • 2 comments

When using apple auth scopes "email", "name" the current provided not parse POST response for get "first_name" and "last_name".

pasifus avatar Nov 19 '22 17:11 pasifus

I found why :

Here: https://github.com/markbates/goth/blob/dcd837795bb225182b7ca6a6ac86ca4e79ace5ec/gothic/gothic.go#L199

We check that params.Encode() == "",

But in the comment it is said

https://github.com/markbates/goth/blob/dcd837795bb225182b7ca6a6ac86ca4e79ace5ec/gothic/gothic.go#L157

And the provider is never removed from the params, making the code that use the form unreachable.

I'll try to push a PR but I might not have time for this

adrien-hearthands avatar Aug 30 '24 00:08 adrien-hearthands

As a workaround I passed a new context with the provider in there instead of passing it through the params.

Like so:

func appleCallback(res http.ResponseWriter, req *http.Request) {
  ctx := context.WithValue(req.Context(), "provider", "apple")

  user, err := gothic.CompleteUserAuth(res, req.WithContext(ctx))
  if err != nil {
    fmt.Fprintln(res, err)
    return
  }
  t, _ := template.New("foo").Parse(userTemplate)
  t.Execute(res, user)
}

p.Post("/oauth/apple", appleCallback)

adrien-hearthands avatar Aug 30 '24 00:08 adrien-hearthands