Ejemplo n.º 1
0
/*
|--------------------------------------------------------------------------
| Application Routes
|--------------------------------------------------------------------------
|
| Here is where you can register all of the routes for an application.
| It's a breeze. Simply tell Laravel the URIs it should respond to
| and give it the controller to call when that URI is requested.
|
*/
Route::get('/', ['as' => 'home', 'uses' => 'WelcomeController@index']);
Route::get('/auth/login', ['as' => 'login', 'uses' => 'WelcomeController@login']);
Route::get('/logout', ['as' => 'logout', 'uses' => 'WelcomeController@logout']);
Route::get('/auth0/callback', ['as' => 'logincallback', 'uses' => '\\Auth0\\Login\\Auth0Controller@callback']);
Route::get('/dump', ['as' => 'dump', 'uses' => 'WelcomeController@dump', 'middleware' => 'auth']);
Route::get('/spa', ['as' => 'spa', 'uses' => 'WelcomeController@spa']);
Route::get('/api/ping', ['as' => 'api', 'uses' => 'WelcomeController@api', 'middleware' => 'auth0.jwt']);
Route::get('/api/protected', array('middleware' => 'auth0.jwt', function () {
    return "Hello " . Auth0::jwtuser()->name;
}));
Route::group(['prefix' => 'api', 'middleware' => ['cors', 'auth0.jwt']], function () {
    Route::post('post', 'TestController@index');
    Route::post('user', 'UserController@update');
    Route::get('/mobilecsrf', function () {
        return csrf_token();
    });
    Route::get('obra/show', 'ObraController@show');
    Route::post('obra/save', 'ObraController@save');
    Route::get('obra/show/{id}', 'ObraController@buscar');
    Route::get('obra/proximas', 'ObraController@getProximas');
});
Ejemplo n.º 2
0
<?php

Route::get('/api/protected', array('before' => 'auth-jwt', function () {
    return "Hello " . Auth0::jwtuser()->name . " this is the Laravel API";
}));
Ejemplo n.º 3
0
// This is a secured url
Route::get('users', array('before' => 'auth', function () {
    $users = User::all();
    return View::make('users')->with('users', $users);
}));
// Configure the auth0 callback
Route::get('/auth0/callback', 'Auth0\\Login\\Auth0Controller@callback');
Route::get('/login', function () {
    return View::make('login');
});
Route::get('/logout', function () {
    Auth::logout();
    return Redirect::home();
});
// This is the hook from the plugin that lets us know that a user has logged in
// and we should either return the real db user or create a new one
// This should be somewhere else.
Auth0::onLogin(function ($auth0User) {
    // See if the user exists
    $user = User::where("auth0id", $auth0User->user_id)->first();
    if ($user === null) {
        // If not, create one
        $user = new User();
        $user->email = $auth0User->email;
        $user->auth0id = $auth0User->user_id;
        $user->nickname = $auth0User->nickname;
        $user->name = $auth0User->name;
        $user->save();
    }
    return $user;
});