DEV Community

API Authentication via Social Networks in Laravel 9 using Sanctum with Socialite

Siddhu on October 16, 2021

Laravel Sanctum with Socialite Earlier I have written, How to use Laravel Sanctum and user authentication using API Now, I'm going to a...
Collapse
 
zaidshahid profile image
zaid-shahid

How can we test it using postman, please answer.

Collapse
 
siddhartha profile image
Siddhu • Edited

I'm not sure, How to test using Postman.

You need at least one sample html page with some google js code

Collapse
 
siddhartha profile image
Siddhu

I'll send you git repo, you can download

Collapse
 
codeperl profile image
mohammad ahsrafuddin ferdousi

Hi Sidhhu,

It's a nice article and thanks for this. I will use this to my new project. As others, I am also curious about the test code and so, is it possible to share the github repo to me too?

Thanks in advance!

Thread Thread
 
siddhartha profile image
Siddhu

Sure, I'll share

Thread Thread
 
siddhartha profile image
Siddhu
Thread Thread
 
codeperl profile image
mohammad ahsrafuddin ferdousi • Edited

Thank you! I will surely help me to look forward!

Update: I was checking the codebase you share. It seems that mistakenly there are no test code for sanctum + socialite?

Thread Thread
 
siddhartha profile image
Siddhu

You are right, I lost some where.

Anyway I'm doing with with new instance with laravel 9.

I'll update the article

Thread Thread
 
codeperl profile image
mohammad ahsrafuddin ferdousi

That's so helpful!

However, I am facing an issue. If somehow you may suggest me any article in such case, I'll be glad Sidhhu.

I am deploying my nuxt app using nginx as reverse proxy server in one docker container.

I deployed my laravel api in another docker container and using nginx as webserver.

Now, even if everything done quite okay "to me" by fixing cors, when calling api from nuxt app it shows this error in chrome:

Access to XMLHttpRequest at 'https://api.laraecom.com/api/v1/users/auth/social/login' from origin 'https://laraecom.com:4430' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: The 'Access-Control-Allow-Origin' header contains multiple values 'https://laraecom.com:4430, *', but only one is allowed.

If you can suggest anything that will be a great help! I am stuck here more than a week!

Thanks in advance!

Thread Thread
 
siddhartha profile image
Siddhu

You have to enable cors

This article will help you dev.to/keikesu0122/a-simple-way-to...

Collapse
 
the_olusolar profile image
Solar

Hi, please can I get the repo too?
I really need to implement this via API instead of browser

Collapse
 
melenchenko profile image
melenchenko • Edited

In this example you show generated access token in browser to end-user via headers. How can I transfer this token to frontend application for further authentications of API requests to my server?

Collapse
 
medilies profile image
medilies

I demonstrated that here dev.to/medilies/laravel-spa-oauth-...

Collapse
 
marienmupenda profile image
Marien Mupenda

Thank for this article.

I can see the call back returns a JSON response, will the response be displayed to the end user on it's browser ?

I am wondering if we should display the response or redirect or something mon user friendly.

Collapse
 
hernanarica profile image
Hernán Arica

in this way I can not authenticate with a frontend made in react

Collapse
 
medilies profile image
medilies
Collapse
 
hanifullahjamalzai profile image
HanifullahJamalzai

I would love to implement Socialite for blog posts not for admin dashboard, I have lost my way how to implement.

Thanks in advance

Collapse
 
siddhartha profile image
Siddhu

You can follow above mentioned steps, if you stuck or doubt anywhere. Pls comment here.

I'll try to provide solutions to my best

Collapse
 
bekzhan99 profile image
Bekzhan

i use two domains one api.beta.website second beta.website. when I make a request through the beta on the socialite it gives errors

Collapse
 
siddhartha profile image
Siddhu

what error that you are facing?

Collapse
 
bekzhan99 profile image
Bekzhan

I make a request through the beta domain to api.beta and there is a request on Google and there is a cors error

Thread Thread
 
siddhartha profile image
Siddhu

Understood, this will help you out. medium.com/@martinsOnuoha/fix-cors...