issueAccessToken() public static method

Issue an access token if the request parameters are valid.
public static issueAccessToken ( ) : array
return array a response object for the protocol in use
Esempio n. 1
1
 /**
  * @author LAHAXE Arnaud
  *
  * @apiGroup Auth
  * @apiName login
  * @api      {post} /oauth/access_token Authenticate user
  *
  * @apiParam {String} username Username.
  * @apiParam {String} password Password.
  * @apiParam {String} grant_type Grant type (password).
  * @apiParam {String} client_id Client id.
  * @apiParam {String} client_secret Client secret.
  *
  * @apiUse NotAuthorized
  *
  * @apiSuccess (200) {String} access_token
  * @apiSuccess (200) {String} token_type
  * @apiSuccess (200) {Datetime} expires_in
  * @apiSuccess (200) {String} refresh_token
  *
  * @return \Symfony\Component\HttpFoundation\Response
  */
 public function login()
 {
     try {
         return response()->json(\Authorizer::issueAccessToken());
     } catch (InvalidCredentialsException $e) {
         return response()->json([], 401);
     }
 }
 public function generateToken()
 {
     try {
         $result = \Authorizer::issueAccessToken();
         \Session::set('token', array_get($result, 'access_token'));
         return redirect()->back();
     } catch (OAuthException $e) {
         return redirect()->with('error', $e->getMessage());
     }
 }
 public function login(Request $request)
 {
     $input = $request->all();
     $return = \Authorizer::issueAccessToken();
     $AccessToken = new AccessToken();
     $user = $AccessToken->getData($return['access_token']);
     if ($user) {
         $me = $this->userRepository->getMe($user->id);
         $return['features'] = $me['features'];
     }
     return Response::json($return);
 }
Esempio n. 4
0
 /**
  * @param Request $request
  * @return \Illuminate\Http\RedirectResponse|\Laravel\Lumen\Http\Redirector
  */
 public function login(Request $request)
 {
     // set default web oauth client
     Input::merge(['client_id' => Config::get('oauth2.web_client.client_id')]);
     Input::merge(['client_secret' => Config::get('oauth2.web_client.client_secret')]);
     Input::merge(['grant_type' => 'password']);
     try {
         \Authorizer::issueAccessToken();
         return redirect('/');
     } catch (\Exception $e) {
         $request->session()->flash('error', 'auth.login_error');
         return redirect(route('auth.loginForm'));
     }
 }
Esempio n. 5
0
 public function signupOrSignin()
 {
     $input = Input::all();
     try {
         $user = $this->service->getUserByEmail($input['email']);
         \Authorization::attempt(['email' => Input::get('username'), 'password' => Input::get('password')]);
         $user = \Authorization::user();
         $transformer = \App::make(\HOFB\Users\UserTransformer::class);
         $response = \Authorizer::issueAccessToken();
         $transformed = $transformer->transform($user);
         $response['user'] = $transformed;
         return \Response::json($response);
     } catch (NotFoundModelException $e) {
         $input['userable_type'] = UserController::filterToType($input['userable_type']);
         $model = $this->service->createUser($input);
         return $this->returnUserModel($model);
     }
 }
Esempio n. 6
0
 /**
  * Store a newly created resource in storage.
  *
  * @return Response
  */
 public function store()
 {
     $user = User::findByEmailAndPassword(Input::get('username'), Input::get('password'));
     if (!isset($user)) {
         return Response::json(array('error' => Config::get('constants.STATUS_CODES.USER.USER_NOT_EXISTS'), 'error_description' => 'User does not exist'), 403);
     } elseif (!$user->activated) {
         return Response::json(array('error' => Config::get('constants.STATUS_CODES.USER.NEED_ACTIVATED'), 'error_description' => 'You need to activate your account', 'data' => $user->toArray()), 403);
     } else {
         try {
             $obj = Authorizer::issueAccessToken();
             $access_token = $obj['access_token'];
             User::invalidOldTokens($access_token);
             return Response::json($obj);
         } catch (\League\OAuth2\Server\Exception\OAuthException $exception) {
             //\Log::error($exception);
             return Response::json(array('error' => $exception->errorType, 'error_description' => $exception->getMessage()), 403);
         }
     }
 }
Esempio n. 7
0
<?php

/*
|--------------------------------------------------------------------------
| 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('/', function () {
    return view('layout');
});
Route::post('oauth/access_token', function () {
    return Response::json(Authorizer::issueAccessToken());
});
Route::group(['before' => 'oauth'], function () {
    Route::resource('user', 'UserController', ['except' => ['create', 'edit']]);
});
Esempio n. 8
0
<?php

/*
|--------------------------------------------------------------------------
| 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('/', 'WelcomeController@index');
$router->group(['prefix' => '/api/v1', 'before' => 'oauth2'], function ($router) {
    $router->resource('users', 'UserController');
    $router->resource('posts', 'PostController');
    $router->resource('news', 'NewsController');
    $router->resource('comments', 'CommentController');
    $router->resource('question-type', 'QuestionTypeController');
    $router->resource('question', 'QuestionController');
    $router->resource('question.answer', 'QuestionAnswerController');
});
Route::post('oauth/access_token', function () {
    return Authorizer::issueAccessToken();
});
Esempio n. 9
0
 *         client_id=f3d259ddd3ed8ff3843839b
 *         client_secret=4c7f6f8fa93d59c45502c0ae8c4a95b
 *         username=api_user
 *         password=api
 *         // http://localhost/api-laravel/public/api/oauth/access_token?grant_type=password&client_id=web&client_secret=4c7f6f8fa93d59c45502c0ae8c4a95b&username=api_user&password=api
 * @return token contain json data
 */
$api->post('oauth/access_token', function () {
    // User try to login or registered
    $accessToken = \Authorizer::issueAccessToken();
    // $user_id = \Authorizer::getResourceOwnerId();
    return \Response::json($accessToken);
});
$api->post('refresh-token', function () {
    // User try to login or registered
    $accessToken = \Authorizer::issueAccessToken();
    // $user_id = \Authorizer::getResourceOwnerId();
    return \Response::json($accessToken);
});
/**
 * Route list those must require authentications
 */
$api->group(['middleware' => 'api.auth'], function ($api) {
    /**
     * Get current loggedin User with api access
     */
    $api->get('user', function () {
        $user = app('Dingo\\Api\\Auth\\Auth')->user();
        return $user;
    });
    /**
Esempio n. 10
0
<?php

/*
|--------------------------------------------------------------------------
| 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('/', 'WelcomeController@index');

Route::get('home', 'HomeController@index');

Route::controllers([
	'auth' => 'Auth\AuthController',
	'password' => 'Auth\PasswordController',
]);
*/
Route::group(array('prefix' => 'api/v1.2'), function () {
    Route::resource('makers', 'MakerController', ['except' => ['create', 'edit']]);
    Route::resource('files', 'FileController', ['except' => ['create', 'edit']]);
    Route::resource('vehicles', 'VehicleController', ['only' => ['index']]);
    Route::resource('makers.vehicles', 'MakerVehiclesController', ['except' => ['edit', 'create']]);
    Route::post('oauth/access_token', function () {
        return response()->json(Authorizer::issueAccessToken());
    });
});
Esempio n. 11
0
    return Response::json(Authorizer::issueAccessToken());
});
$api = app('api.router');
$api->version('v1', ['middleware' => 'oauth'], function ($api) {
    $api->get('users/{id}', 'Api\\V1\\UserController@show');
    $api->post('users/register', 'Api\\V1\\UserController@register');
});
$api->version('v1', function ($api) {
    $api->post('users/register', 'Api\\V1\\UserController@register');
});
//  	$api->group(['protected' => true],function($api){
//  		//需要保护的路由
//  		$api->get('user/{id}', 'Api\V1\UserController@show');
//  	});
Route::post('/access_token', function (Request $request) {
    try {
        $response = Authorizer::issueAccessToken();
        return new Response(json_encode($response), 200, ['Content-type' => 'application/json', 'Cache-Control' => 'no-store', 'Pragma' => 'no-store']);
    } catch (OAuthException $e) {
        return new Response(json_encode(['error' => $e->errorType, 'message' => $e->getMessage()]), $e->httpStatusCode, $e->getHttpHeaders());
    }
});
///
$api->version('v1', ['middleware' => 'api.auth'], function ($api) {
    $api->get('user', ['scopes' => 'read_user_data', function () {
        // Only access tokens with the "read_user_data" scope will be given access.
    }]);
});
//中间件加参数模式
// Route::put('post/{id}', ['middleware' => 'role:editor,delete', function ($id) {
// }]);
Esempio n. 12
0
        //dd($redirectUri);
        $string = array();
        $string = str_split($redirectUri, 29);
        $code = $string[1] . $string[2];
        if ($redirectUri == true) {
            $redirectUri = 'oauth/access_token?grant_type=authorization_code&client_id=1&client_secret=shelves&redirect_uri=http://localhost:34000/&code=' . $code;
        }
    }
    // if the user has denied the client to access its data, redirect back to the client with an error message
    if (Input::get('deny') !== null) {
        $redirectUri = Authorizer::authCodeRequestDeniedRedirectUri();
    }
    return Redirect::to($redirectUri);
}]);
Route::get('oauth/access_token', function () {
    $access_token[] = Authorizer::issueAccessToken();
    //dd($access_token);
    return redirect('/protected-resource?access_token=' . $access_token[0]['access_token']);
});
Route::get('/auth/login', function () {
    if (Auth::loginUsingId(1)) {
        return 'A user is logged in';
    } else {
        return 'No user is logged in ';
    }
});
Route::get('/home', function () {
    return view('home');
});
// Authentication routes...
Route::get('auth/login', 'Auth\\AuthController@getLogin');
Esempio n. 13
0
*/
Route::get('/', function () {
    return view('welcome');
});
Route::controllers(['auth' => 'Auth\\AuthController', 'password' => 'Auth\\PasswordController']);
//Route::group(['prefix'=>'api/v1.1'],function() {
Route::resource('accounts', 'AccountController', ['except' => ['create', 'edit']]);
Route::resource('transactions', 'Transaction\\TransactionController', ['only' => ['create', 'show', 'index', 'store']]);
Route::resource('activities', 'ActivityController', ['only' => ['create', 'show', 'index', 'store']]);
Route::resource('accounts.transactions', 'AccountTransactionController', ['except' => ['edit', 'create', 'update', 'edit']]);
//});
Route::post('oauth/access_token', function () {
    return Authorizer::issueAccessToken()['access_token'];
});
Route::post('access/token', function () {
    $_REQUEST['access_token'] = Authorizer::issueAccessToken()['access_token'];
    return $_REQUEST;
});
Route::get('queue', function () {
    Queue::push('SendData', '', 'nfc');
    Queue::push('SendDataK', '', 'kudotsu');
    return "ok!";
});
Route::post('queue/demo', function () {
    return Queue::marshal();
});
Route::get('mail', function () {
    //    dd(\Illuminate\Support\Facades\Config::get('mail'));
    $data = [];
    Mail::send('emails.welcome', $data, function ($message) {
        $message->to('*****@*****.**')->subject('From mail, your one-time PIN is ' . time() . '. It will expire in 5 minutes.');