dimanche 1 juillet 2018

Create password grant access token and refresh token after user register

Currently, I'm using personal access token for authentication when user register to site. like this.

/**
* Register api 
* 
* @return \Illuminate\Http\Response 
*/ 

public function register(Request $request) 
{ 
    $validator = Validator::make($request->all(), [ 
        'name' => 'required|string|max:255',
        'email' => 'required|string|email|max:255|unique:users',
        'password' => 'required|string|min:6|confirmed',
        'type' => 'required|string|max:50'
    ]);
if ($validator->fails()) { 
        return response()->json(['error'=>$validator->errors()], 401); 
    }
$input = $request->all(); 
    $input['password'] = bcrypt($input['password']); 
    $user = User::create($input); 
    $success['token'] =  $user->createToken('MyApp')-> accessToken; 
    $success['name'] =  $user->name;
return response()->json(['success'=>$success], $this-> successStatus); 
}

Now, I want to use password grant token so I can set token's expiry time from AuthServiceProvider simply by writing 1 line Passport::tokensExpireIn(now()->addDays(15));

My question is in register method shown in above code after user create and store in DB how can I call passport's route (/oauth/token with params: grant_type, client_id, client_secret, username, password) for create access token and refresh token?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire