Пример #1
0
 public function register(Application $app)
 {
     $app['controller.oauth.authorization'] = $app->share(function ($app) {
         $server = new AuthorizationServer();
         $server->setSessionStorage(new SessionStorage());
         $server->setAccessTokenStorage(new AccessTokenStorage());
         $server->setRefreshTokenStorage(new RefreshTokenStorage());
         $server->setClientStorage(new ClientStorage());
         $server->setScopeStorage(new ScopeStorage());
         $server->setAuthCodeStorage(new AuthCodeStorage());
         $server->addGrantType(new AuthCodeGrant());
         $server->addGrantType(new RefreshTokenGrant());
         /* @var Locator $spot */
         $spot = $app['spot'];
         $userMapper = $spot->mapper(\OpenCFP\Domain\Entity\User::class);
         $speakerRepository = new SpotSpeakerRepository($userMapper);
         /* @var Sentry $sentry */
         $sentry = $app['sentry'];
         $controller = new AuthorizationController($server, new SentryIdentityProvider($sentry, $speakerRepository));
         $controller->setApplication($app);
         return $controller;
     });
     $app['controller.oauth.clients'] = $app->share(function ($app) {
         /* @var Locator $spot */
         $spot = $app['spot'];
         return new ClientRegistrationController($spot->mapper(\OpenCFP\Domain\OAuth\Client::class), $app['spot']->mapper(\OpenCFP\Domain\OAuth\Endpoint::class), $app['security.random']);
     });
 }
 public function test_with_server_error()
 {
     AuthorizationServer::shouldReceive('checkAuthorizeParams')->once()->andThrow(new Exception('Internal Server Error'));
     $response = $this->getFilter()->filter('', '', null);
     $this->assertTrue($response instanceof Illuminate\Http\JsonResponse);
     $this->assertTrue($response->isServerError());
 }
 public function getAuthorizationCode()
 {
     // get the data from the check-authorization-params filter
     $params = Session::get('authorize-params');
     // get the user id
     $params['user_id'] = Auth::user()->id;
     // check if the user approved or denied the authorization request
     if (Input::get('approve') !== null) {
         $code = AuthorizationServer::newAuthorizeRequest('user', $params['user_id'], $params);
         Session::forget('authorize-params');
         return Redirect::to(AuthorizationServer::makeRedirectWithCode($code, $params));
     }
     if (Input::get('deny') !== null) {
         Session::forget('authorize-params');
         return Redirect::to(AuthorizationServer::makeRedirectWithError($params));
     }
 }
    //
    //		$code = AuthorizationServer::newAuthorizeRequest('user', $params['user_id'], $params);
    //
    //		Session::forget('authorize-params');
    //
    //		return Redirect::to(AuthorizationServer::makeRedirectWithCode($code, $params));
    //	}
    //
    //	if (Input::get('deny') !== null) {
    //
    //		Session::forget('authorize-params');
    //
    //		return Redirect::to(AuthorizationServer::makeRedirectWithError($params));
    //	}
}));
Route::get('callback', function () {
    return View::make('accesstoken-form');
});
// @see https://github.com/lucadegasperi/oauth2-server-laravel#issuing-an-access-token
Route::post('oauth/access_token', function () {
    return AuthorizationServer::performAccessTokenFlow();
});
Route::get('scope1', array('before' => 'oauth:scope1', function () {
    return 'scope1 allowed';
}));
Route::get('scope2', array('before' => 'oauth:scope2', function () {
    return 'scope2 allowed';
}));
Route::get('scope3', array('before' => 'oauth:scope3', function () {
    return 'scope3 allowed';
}));
Пример #5
0
 /**
  * Login the driver.
  *
  * @return array|\Illuminate\Http\JsonResponse
  */
 public function login()
 {
     return \AuthorizationServer::performAccessTokenFlow();
 }
Пример #6
0
    $params = Session::get('authorize-params');
    $params['user_id'] = Auth::user()->id;
    $app_details = \OAuthApp::where('client_id', $params['client_id'])->first();
    return View::make('partials.oauth.forms.authorization-form', array('params' => $params, 'app_details' => $app_details));
}));
Route::post('oauth/authorize', array('before' => 'check-authorization-params|auth|csrf', function () {
    $params = Session::get('authorize-params');
    $params['user_id'] = Auth::user()->id;
    if (Input::get('approve') !== null) {
        $code = AuthorizationServer::newAuthorizeRequest('user', $params['user_id'], $params);
        Session::forget('authorize-params');
        return Redirect::to(AuthorizationServer::makeRedirectWithCode($code, $params));
    }
    if (Input::get('deny') !== null) {
        Session::forget('authorize-params');
        return Redirect::to(AuthorizationServer::makeRedirectWithError($params));
    }
}));
Route::get('secure-route', array('before' => 'oauth:basic', function () {
    return "oauth secured route ";
}));
/*
|------------------------------------------------------------------
| For routes that don't exist
|------------------------------------------------------------------
*/
App::missing(function ($exception) {
    if (Request::segment(1) == "data" || Request::segment(1) == "api") {
        $error = array('error' => true, 'message' => $exception->getMessage(), 'code' => $exception->getStatusCode());
        return Response::json($error, $exception->getStatusCode());
    } else {
Пример #7
0
 /**
  * Register Order resource Routes
  *
  * @return void
  */
 public function registerRoutes()
 {
     $this->app['router']->post('oauth2/access_token', function () {
         return \AuthorizationServer::performAccessTokenFlow();
     });
 }
 public function postTestAuthorize()
 {
     if (!array_key_exists('X_ALLOW_TEST_AUTH', $_SERVER) || $_SERVER['X_ALLOW_TEST_AUTH'] != 'true') {
         return;
     }
     $data = ['eduPersonPrincipalName' => Input::get('eduPersonPrincipalName'), 'eduPersonScopedAffiliation' => Input::get('eduPersonScopedAffiliation'), 'sn' => Input::get('sn'), 'givenName' => Input::get('givenName'), 'mail' => Input::get('mail')];
     $user = (object) $data;
     $userId = Input::get('eduPersonPrincipalName');
     $owner = Owner::find($userId);
     if (!$owner) {
         $owner = new Owner();
         $owner->id = $userId;
     }
     $owner->data = json_encode($user);
     $owner->save();
     $params = Session::get('authorize-params');
     $params['user_id'] = $user->eduPersonPrincipalName;
     if (Input::get('approve') !== null) {
         $code = AuthorizationServer::newAuthorizeRequest('user', $params['user_id'], $params);
         Session::forget('authorize-params');
         return Redirect::to(AuthorizationServer::makeRedirectWithCode($code, $params));
     }
     if (Input::get('deny') !== null) {
         Session::forget('authorize-params');
         $url = AuthorizationServer::makeRedirectWithError($params);
         return new \Illuminate\Http\RedirectResponse((string) $url, 302, array());
     }
 }