20

I want to build an app with laravel 5 & dropbox API in which I want the API allow/cancel-warning to be displayed when you land on the homepage, not when you click a button. I tried different methods but I couldn`t make it work.

public function start(){
        session(['user_id'=>1]);
        $dKey = 'key';
        $dSecret = 'secret';
        $appName = 'app';

        $appInfo = new Dropbox\AppInfo($dKey,$dSecret);

        //store csrf token
        $tokenStore = new  Dropbox\ArrayEntryStore($_SESSION,'dropbox-auth-csrf-token');
        //define auth details
        $this->webAuth = new Dropbox\WebAuth($appInfo,$appName,'http://localhost:8000/dropbox/finish',$tokenStore);
        $this->checkSession();
    }

    public function checkSession(){
        $users = User::where('id','=',session('user_id'))->get();

        if(isset($user[0]->dropbox_token)){

        }
        else{
            $url = $this->webAuth->start();

            //return Redirect::to($url);
            //return Redirect::away($url);
            //header('Location : '.$url);
        }

    }

The link in $url exists and its valid.

These(last 3 commented methods) are the methods i tried , including return redirect($url),is it possible to do this or am i wasting my time with this ?please help me out.

Shiro
  • 7,344
  • 8
  • 46
  • 80
She Fu
  • 261
  • 1
  • 3
  • 9
  • 1
    When you say "I couldn't make it work," what specifically happened (for each of the things you tried)? From a cursory glance at the Laravel docs, I think that `return redirect()->away($url);` should be right. Have you tried that? – user94559 Mar 20 '15 at 02:18
  • (Perhaps `Redirect::away($url)` is the same thing... what actually happens when you try that?) – user94559 Mar 20 '15 at 02:19
  • Oh, maybe you're missing a `return` in `start()`? It should probably be `return $this->checkSession();`. – user94559 Mar 20 '15 at 02:29

4 Answers4

39

This code works for me:

return redirect()->away('https://www.dropbox.com');

Make sure you also add a return (i.e. return $this->checkSession();) in start().

user94559
  • 59,196
  • 6
  • 103
  • 103
9

Below code will work

return redirect()->away('http://www.paypal.com');

And this will also work.

return redirect('http://www.paypal.com');
Pankaj Makwana
  • 3,030
  • 6
  • 31
  • 47
  • I am trying to achieve the same thing with WSO2 as an IdP and my Application Server which is Ubuntu-Based s Service Provider. I am using mod_auth_mellon with Laravel and I keep on getting 500 server error. I had thought these suggestions will work for me but it doesn't seem like it. So frustrating. – scruffycoder86 Aug 31 '17 at 12:57
3

For https and such use the following

return redirect()->to($refererUrl);
Harry Bosh
  • 3,611
  • 2
  • 36
  • 34
0

Can do this,

use Redirect;

return Redirect::to('your url');

Or just,

return \Redirect::to('your url');
vimuth
  • 5,064
  • 33
  • 79
  • 116