boraxpr / nuxtjs-supabase

https://nuxtjs-supabase.vercel.app
2 stars 1 forks source link

[NOTE] OAuth2 : Google, Facebook, Line #23

Open boraxpr opened 8 months ago

boraxpr commented 8 months ago

Google, Facebook : Supabase Supported

const { data, error } = await supabase.auth.signInWithOAuth({ provider: 'google' })

const { data, error } = await supabase.auth.signInWithOAuth({ provider: 'facebook' })

Line : Unsupported by Supabase
- Secure Workaround : Using magic link and Auth Admin (Must be done on Server side /server )
- Flow _Study <https://developers.line.biz/en/docs/line-login/integrate-line-login/#page-title>_
1. **Login** Button <https://developers.line.biz/en/docs/line-login/login-button/#design-guidelines>
2. Line **Authorize** with scope="profile%20openid%20email" to also get profile image, email
<https://developers.line.biz/en/docs/line-login/integrate-line-login/#making-an-authorization-request>
3. **Callback** (You will receive "**code**" and "**state**")<https://developers.line.biz/en/docs/line-login/integrate-line-login/#receiving-the-authorization-code-or-error-response-with-a-web-app>
4. **Issue Access Token** By using "code",  (line developer) client_id, client_secret (/line developer) <https://developers.line.biz/en/reference/line-login/#issue-access-token>
5. From 4. Issuing you will get **id_token** : id_token is JWT (JWT= Header + Payload + Signature). Here, you will get user info from the payload. After decoding JWT, use the email to do admin.createUser and email_confirm:true to auto activate account for Line logging-in user
```js
const client = serverSupabaseServiceRole(event)
const { data, error } = await client.auth.admin.createUser({
  email: 'email_from_line_id_token@email.com',
  email_confirm: true
})

const { data, error } = await client.auth.signInWithOtp({
  email: 'email_from_line_id_token@email.com',
})

However, this only suits the case that the Line user has email For cases that user does not have email (All Line users must have phone_number), https://developers.line.biz/en/docs/partner-docs/line-profile-plus/#page-title, You must contact Line as a company representative (Official Account) about LINE Profile+ Service which can only be obtained by corporate users who have undergone the application process by LINE.