https://supertokens.com/ logo
Title
a

artico

02/27/2023, 7:31 PM
Hi guys! I´m trying to understand how to get third-party user´s first and last name... I´ve enabled metadata feature and added scope https://www.googleapis.com/auth/userinfo.profile to google provider - but those fields are not set. Please suggest what I´m doing wrong?
r

rp

02/28/2023, 5:31 AM
hey @artico you need to set those manually in the user metadata recipe.
a

artico

02/28/2023, 5:33 AM
thanks @rp , but how do i get them? is there an example gist or something?
r

rp

02/28/2023, 5:37 AM
which recipe are you using?
a

artico

02/28/2023, 5:37 AM
ThirdPartyEmailPassword
a

artico

02/28/2023, 5:40 AM
ok, and after "let accessToken =..." i have to call google api to get the names, right? and the same goes to apple as well?
r

rp

02/28/2023, 5:42 AM
yes
a

artico

02/28/2023, 5:47 AM
thank you! by the way, under the hood supertokens use the new Google Identity Services for Web solution, or rely on the old Google Sign-In JavaScript platform library for Web is set to be deprecated after March 31, 2023 ?
r

rp

02/28/2023, 5:48 AM
@sattvikc can answer this.
s

sattvikc

02/28/2023, 5:48 AM
will get back in a moment
@artico you are right about fetching name for google. but for apple, there is no separate API that provides user info. Also, it's sent back in a different way. May I know which language are you using for backend? I'll help you with a sample code snippet which you could use as a reference
a

artico

02/28/2023, 6:12 AM
i use nest.js
s

sattvikc

02/28/2023, 6:15 AM
and about the google identity service, we don't use the javascript platform library. we use standard open-id/oauth2 approach.
I'm little busy right now, I'll share the apple snippet whenever I get some time to look into it.
a

artico

02/28/2023, 7:18 AM
@sattvikc if i´d like to work with both google and apple in the same override, i have to distinguish them by input.provider.id, right?
s

sattvikc

02/28/2023, 7:18 AM
right
a

artico

02/28/2023, 7:22 AM
i have success with google, by change do you have time to give me apple example, please?
@sattvikc i tried to set scope in config as 'email name' and noticed that in the URL it appears as 'email+name', however according to apple docs it has to be like 'email%20name' https://developer.apple.com/documentation/sign_in_with_apple/sign_in_with_apple_js/incorporating_sign_in_with_apple_into_other_platforms#3332113 wondering if it can cause an issue.
s

sattvikc

02/28/2023, 9:46 AM
scope should be an array, plz set it to ['email', 'name']
a

artico

02/28/2023, 9:55 AM
@sattvikc i set it to array for both google and apple, however resulting URLs differ: https://accounts.google.com/o/oauth2/v2/auth/oauthchooseaccount?scope=email%20profile... https://appleid.apple.com/auth/authorize?scope=email+name... google's one seems right, but apple's not. not sure where this happens, maybe on supertokens side which makes the redirect
@sattvikc anyway, if you have working example of getting apple user fullname - that means it works with both + and %20... could you please share the example
s

sattvikc

02/28/2023, 10:28 AM
+ and %20 mean the same in the URL
but, the way name is returned by the apple is different. it would need some amount of time to write the sample. I'll share whenever I get some time for this.
r

rp

02/28/2023, 10:37 AM
hey @artico - unfortunately we won't be able to help you with the name issue with apple at the moment. You can try and solve it yourself using our overrides feature. That being said, we are working on fixing this issue entirely in our SDK and will release this in 1-2 months time
a

artico

02/28/2023, 11:36 AM
@rp ok i will try.. please suggest how can i get original apple response in the override function?
@sattvikc according to apple docs, user name should be in the response: https://developer.apple.com/documentation/sign_in_with_apple/sign_in_with_apple_js/incorporating_sign_in_with_apple_into_other_platforms#3332115 user - A JSON string containing the data requested in the scope property. The returned data is in the following format: { "name": { "firstName": string, "lastName": string }, "email": string }
@rp @sattvikc after some investigation i found that user data goes from apple via post request to the redirectURI, which is https://supertokens.io/dev/oauth/redirect-to-app - if i try to change it apple returns error, so i guess it's tied to client_id internally? is there a way to change this uri to handle the response on my side?
r

rp

02/28/2023, 2:29 PM
You need to use your own apple keys and can set the callback url on your side
a

artico

02/28/2023, 2:55 PM
@rp if i specify my own redirect URI - what is the default path on my own supertokens setup to handle that? or this handler exists only on your site?
r

rp

02/28/2023, 3:00 PM
It will be your apiDomain/auth/callback/apple
(This is also mentioned in our docs)
a

artico

02/28/2023, 3:12 PM
thank you @rp ! and the last question: is it possible to get request data from apple using override or i have to fork and modify source code for that?
r

rp

02/28/2023, 3:13 PM
You can get the request data. It should be available in the input.options.req object (if you are using node SDK)
d

Davido

03/10/2023, 2:36 AM
@artico did you get this working? I do not see the value in the input.options.req object. I'm calling both getFormData and getJSONBody and don't see it in either. I think the second post is overriding the value. I see a POST to /api/auth/callback/apple and then another to /api/auth/signinup and I can only retrieve the values from the second.
r

rp

03/10/2023, 4:14 AM
Perhaps @sattvikc can help here.
s

sattvikc

03/10/2023, 4:28 AM
may I see your supertokens init and overrides ?
r

rp

03/10/2023, 10:21 PM
@sattvikc
d

Davido

03/12/2023, 7:35 PM
I've successfully found the value! Is there a recommended way to pipe it to the actual signinupPOST flow?
appleRedirectHandlerPOST: async function (input) {
                                console.log("REDIRECT INPUT", input)
                                let result = await originalImplementation.appleRedirectHandlerPOST(input)
                                console.log("REDIRECT RESULT", result)
                                let data = await input.userContext?._default?.request?.getFormData() // [Object: null prototype]
                                let user = { ...data }.user
                                console.log("REDIRECT USER", user)

                                return result
                            }
s

sattvikc

03/13/2023, 4:53 AM
Hi @Davido, there is no recommended way to pipe it as of now. for now, you could write your own redirect to the frontend and include the data in that. And then the signInUpPOST will also need some tweaking to be able to send that information again. We are working on new interfaces to be able to do this easily. but, that will take some time to release.
other way you could do is use a temporary table that contains email and user Info, populate it in the apple redirect override. and in the sign in up post, once you get the email of the user, use this temporary table to read and populate the user info
d

Davido

03/13/2023, 2:00 PM
Thanks! I'll take a closer look at those options