Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lumen 7.0 token always return false #2042

Open
Hothi-Jimit opened this issue Oct 7, 2020 · 1 comment
Open

Lumen 7.0 token always return false #2042

Hothi-Jimit opened this issue Oct 7, 2020 · 1 comment
Labels

Comments

@Hothi-Jimit
Copy link

Subject of the issue

Lumen ^7.0 token always return false

Your environment

Q A
Bug? no
New Feature? no
Framework Lumen
Framework version 7.x
Package version ^1.0
PHP version 7.x.y

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.

@stale
Copy link

stale bot commented Dec 25, 2020

Is this still relevant? If so, what is blocking it? Is there anything you can do to help move it forward?

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.

@stale stale bot added the stale label Dec 25, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant