You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In my project "laravel/lumen-framework": "^7.0" and "tymon/jwt-auth": "^1.0".
When I creating token that time always returns false.
app/User.php
`<?php
namespace App;
use Illuminate\Auth\Authenticatable;
use Laravel\Lumen\Auth\Authorizable;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Contracts\Auth\Authenticatable as AuthenticatableContract;
use Illuminate\Contracts\Auth\Access\Authorizable as AuthorizableContract;
use Illuminate\Support\Facades\Hash;
use Tymon\JWTAuth\Contracts\JWTSubject;
class User extends Model implements JWTSubject, AuthenticatableContract, AuthorizableContract
{
use Authenticatable, Authorizable;
public $table= "USER_MASTER";
protected $primaryKey = 'USER_ID';
public $incrementing = false;
const CREATED_AT = 'CREATED_DATE';
const UPDATED_AT = 'UPDATED_DATE';
protected $fillable = [
'USER_NAME', 'PASSWORD',
];
protected $hidden = [
'PASSWORD',
];
public function getAuthIdentifierName()
{
return 'USER_NAME';
}
public function getAuthIdentifier()
{
return $this->getId();
}
public function getId()
{
return $this->USER_NAME;
}
public function getPassword()
{
return $this->PASSWORD;
}
public function getAuthPassword()
{
return $this->getPassword();
}
public function getJWTIdentifier()
{
return $this->getId();
}
public function getJWTCustomClaims()
{
return [];
}
public function setPasswordAttribute($value) {
$this->attributes['PASSWORD'] = Hash::make($value);
}
}`
app/Http/Controllers/AuthController.php
`<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\User;
use Tymon\JWTAuth\Contracts\Providers\Auth;
use Tymon\JWTAuth\Facades\JWTAuth;
class AuthController extends Controller
{
public function __construct()
{
//$this->middleware('auth:api', ['except' => ['login']]);
}
public function login(Request $request) {
$user = new User();
$user->USER_ID ='c2aea979-dfdd-4d2d-8457-ff722b2654fe';
$user->USER_NAME = 'test@gmail.com';
$user->PASSWORD = 'Test@123';
$user->DOMAIN_ID ='c2aea979-dfdd-4d2d-8457-ff722b2654fe';
$user->save();
if (! $token = JWTAuth::attempt(['USER_NAME'=>$request->username,'PASSWORD'=>$request->password])) {
return "error";
}
return $this->respondWithToken($token);
}
private function respondWithToken($token) {
return $this->respond([
'token' => $token,
'access_type' => 'bearer',
'expires_in' => auth()->factory()->getTTL() * 60
], "Login Successful");
}
public function logout() {
auth()->logout();
return $this->respondWithMessage('User successfully logged out');
}
public function refresh() {
return $this->respondWithToken(auth()->refresh());
}
public function me() {
return $this->respond(auth()->user());
}
}
`
User insert working perfect but when the same detail hit with postman that return always an error.
Please help me.
Thank you.
The text was updated successfully, but these errors were encountered:
Subject of the issue
Lumen ^7.0 token always return false
Your environment
In my project "laravel/lumen-framework": "^7.0" and "tymon/jwt-auth": "^1.0".
When I creating token that time always returns false.
app/User.php
`<?php
namespace App;
use Illuminate\Auth\Authenticatable;
use Laravel\Lumen\Auth\Authorizable;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Contracts\Auth\Authenticatable as AuthenticatableContract;
use Illuminate\Contracts\Auth\Access\Authorizable as AuthorizableContract;
use Illuminate\Support\Facades\Hash;
use Tymon\JWTAuth\Contracts\JWTSubject;
class User extends Model implements JWTSubject, AuthenticatableContract, AuthorizableContract
{
use Authenticatable, Authorizable;
public $table= "USER_MASTER";
protected $primaryKey = 'USER_ID';
public $incrementing = false;
const CREATED_AT = 'CREATED_DATE';
const UPDATED_AT = 'UPDATED_DATE';
}`
app/Http/Controllers/AuthController.php
`<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\User;
use Tymon\JWTAuth\Contracts\Providers\Auth;
use Tymon\JWTAuth\Facades\JWTAuth;
class AuthController extends Controller
{
public function __construct()
{
//$this->middleware('auth:api', ['except' => ['login']]);
}
}
`
User insert working perfect but when the same detail hit with postman that return always an error.
Please help me.
Thank you.
The text was updated successfully, but these errors were encountered: