redirect()->intended('/login') not working laravel - laravel

I'm using a custom SocialLoginController to log my users with facebook or google in al Laravel 5.3 project
In some cases I send to users an email with info about one change and the URL to the resource, for example https://myweb.com/settings/profile/[the-uuid]
when the user tries to access but is not logged in, he's redirected to the Handler#render() where I send it to login with return redirect()->guest('/login'); and after login with social account I redirect them using return redirect()->intended('/home') but since I don't use the LoginController, the redirection to the requested URL is not working.
Any idea? Thanks

The problem is the request object is lost after redirect the user to login with facebook or google, so I fixed by saving the requested URI in a session variable and then checking if exists after redirect
return Session::get('intended') ? redirect()->to(\Session::get('intended')) : redirect()->to('/expenses');
Maybe this could help someone

Related

Retrieving session in another domain using nuxtjs and laravel sanctum

Good morning!
Here is the problem i'm facing: (i'm using NuxtJs and Laravel Sanctum)
I have a domain : 'testingdomain.com'
And with this main domain i have subdomains such as :
myfirstdomain.testingdomain.com
myotherdomain.testingdomain.com
connexion.testingdomain.com
my application work this way: i have the connexion.testingdomain.com that help my users getting redirected to the corresponding url for example:
A user 'john.doe#gmail.com' is registered in a company that use the url 'myotherdomain.testingdomain.com' so whenever he write his mail in the input displayed in connexion.testingdomain.com, he will be redirect to the corresponding url which for this example is -> 'myotherdomain.testingdomain.com'.
However if the user is logged in 'myotherdomain.testingdomain.com' and re-enter the 'connexion.testingdomain.com' i would like him to be redirected to the subdomain where he is authentified but i do not know how to achieve this because i can't access the $auth state from the 'myotherdomain.testingdomain.com' (he is logged so this.$auth.loggedIn is true) in 'connexion.testingdomain.com' (this.$auth.loggedIn is set to false)
Has anyone faced a similar problem and could help me ?
Thanks

How to get redirect the given, correct and clean URL after Facebook authentication in Laravel?

I am developing a functionality to allow facebook users to register in our web application. The approach is:
We will create one app on facebook
Facebook authentication plugin (http://developers.facebook.com/docs/guides/web/#login) will be used in our registration page.
When user clicks on facebook button, facebook login page and then app authorization page are shown.
One user allows/disallows facebook app, user will be redirected to the main page(https://example.com)
But it's redirected like this(https://example.com/#=), so I am facing another issue with that.
Appended this characters(#=)
I have tried to fix the url, but it's redirected like that anyway.
Here is the redirection code.
Auth::login($user);
return Redirect::to(URL('/'));
My server is Nginx.
Hope to get solved my problem.
Thanks in advance!
Try to name the route then redirect to it.
Route::get('/', 'HomeController#index')-
>name('home');
then redirect()->to(route('home'));

Laravel passport Oauth2 "Requesting Tokens"

I am working with Zapier, and trying to authenticate user using OAuth2. I am using the Laravel(5.5) Passport(^4.0).
I am trying to use defalut passport routes "https://laravel.com/docs/5.5/passport".
But when it goes to "oauth/authorize" GET method and if user is not logged in then gives me {"error":"Unauthenticated."} instead of redirecting to Login page. And if user is logged in already then worked well.
Is there something i am missing and where I can check to resolve this issue.
Thanks and Regards
You are working with Oauth2 so you will get 401 and {"error" : "Unauthenticated"}. It is up to you to handle the unauthenticated response to the server (e.g. your js front end will redirect or your mobile app show login page).

Laravel + phpCAS: After login, redirect back to same page which required login

I am developing a project using Laravel where we use phpCAS for user authentication. I am using this Laravel package for phpCAS:https://github.com/subfission/cas
After user gets authenticated, i wish to return him/her back to URL from which he/she was redirected to CAS server login.
I used url()->previous(); but it return wrong information in google chrome about referring URL (controller/action).
How can i achieve it? Thanks!
use the intended() method
The intended method on the redirector will redirect the user to the URL they were attempting to access before being intercepted by the authentication middleware. A fallback URI may be given to this method in case the intended destination is not available.
example : return redirect()->intended('dashboard');

How to redirect user back to the next request after login with sentry in laravel 5.3

I am using sentry to authenticate users in laravel 5.3. When the user clicks auth protected route is redirect to the login form. After login, the user is redirected to home page.
How can I configure sentry in manner that the authenticated user is not redirected back to home page but instead to the original destination before login. Kindly assist I seem not to figure it out.
You can use a function called intended
return redirect()->intended('dashboard');
The intended method on the redirector will redirect the user to the URL they were attempting to access before being intercepted by the authentication middleware. A fallback URI may be given to this method in case the intended destination is not available.
https://laravel.com/docs/5.3/authentication#authenticating-users
Maybe this may help you --
You can try giving the url something like this localhost:8000/something?url=anythingelse so that after login change the redirect path to $_GET['url'].
Use a form rather than link to go to login page. Try this --
<form method="GET" url="{{ url('/some') }}?{{ Request::path() }}" id="login"></form>
Login

Resources