I ve managed to add a new column into oauth_access_tokens
table called callback_url
. The problem i ve got is when i am trying to pass callback_url
value into createToken
function.
public function store(Request $request)
{
$this->validation->make($request->all(), [
'name' => 'required|max:255',
'scopes' => 'array|in:'.implode(',', Passport::scopeIds()),
])->validate();
return $request->user()->createToken(
$request->name, $request->callback_url, $request->scopes ?: []
);
}
VUEJS COMPONENT:
store() {
this.accessToken = null;
this.form.errors = [];
axios.post('/user/token', this.form)
.then(response => {
this.form.name = '';
this.form.callback_url = '';
this.form.scopes = [];
this.form.errors = [];
this.tokens.push(response.data.token);
this.showAccessToken(response.data.accessToken);
})
.catch(error => {
if (typeof error.response.data === 'object') {
this.form.errors = _.flatten(_.toArray(error.response.data));
} else {
this.form.errors = ['Something went wrong. Please try again.'];
}
});
},
It works fine without $request->callback_url but with that extra parameter this is an error i am getting back.
Whoops! Something went wrong!
Type error: Argument 2 passed to Models\User::createToken() must be of the type array, string given, called in UserAccessTokenController.php on line 62 Symfony\Component\Debug\Exception\FatalThrowableError/vendor/laravel/passport/src/HasApiTokens.php 64 { "file": "/UserAccessTokenController.php", "line": 62, "function": "createToken", "class": "Models\User", "type": "->" } { "function": "store", "class": "UserAccessTokenController", "type": "->" }
Did anyone had that issue or know how to deal with this problem. Thanks in advance.
Function createToken() accepts only two parameters. I solve my problem by creating a accessToken then updating a result with new callback_url value. Hope that helps.
public function store(Request $request)
{
$token = $request->user()->createToken(
$request->name, $request->scopes ?: []
);
if ($request->callback_url){
$url = $request->callback_url;
$request->user()->tokens()->where( 'id', $token->token->id )->update( [
'callback_url' => $url,
] );
}
return $token;
}