Search code examples
phplaravellinkedin-apilaravel-socialite

Laravel Socialite : Login With LinkedIn Gives Error on Cancle Button


I have followed below link to provide Login With LinkedIn in my laravel app.

https://itsolutionstuff.com/post/laravel-5-login-with-linkedin-using-socialite-packageexample.html

All Working fine , I am successfully able to login with likedin .

But problem is when user first time click button Login With Linked on my website , it redirect to linkedIn Page show Dialog with Ok and Cancle button and now if user click on cancle button then its shows below error

enter image description here

browser url is :

http://www.mywebsite.com/auth/linkedin/callback?error=user_cancelled_login&error_description=The+user+cancelled+LinkedIn+login&state=NSlF7oA3yFRLCoRi5BARhbVrWwK8b02Mg54Jw5cg

I want when user click on cancle button , it simply redirect to home page of my website .

On LinkedIn Developer Console I have added below url :

OAuth 2.0

Authorized Redirect URLs:

http://www.mywebsite.com/auth/linkedin/callback

OAuth 1.0a

Default "Accept" Redirect URL:

http://www.mywebsite.com/auth/linkedin

Default "Cancel" Redirect URL:

http://www.mywebsite.com/

please help me to solve out this issue.


Solution

  • You should try this:

    In Contoller method withch is called for http://www.mywebsite.com/auth/linkedin/callback

    if($request->has('error')){
     return redirect()
                 ->to('admin/login')
                 ->withErrors("Access Denied");
    }