Adldap2 / Adldap2-Laravel

LDAP Authentication & Management for Laravel
MIT License
911 stars 185 forks source link

Implement an additional Interface on Adldap\Models\User #862

Open lazosweb opened 4 years ago

lazosweb commented 4 years ago

Description:

I want to use the NoDatabaseUserProvider which returns the Adldap\Models\User model. On that model we want to use tymondesigns/jwt-auth which will return a JSON Web Token. In order to do that we have to apply an interface on the Adldap\Models\User but we cannot do this without overwriting your package. An alternative way of doing this?

Steps To Reproduce:

stevebauman commented 4 years ago

Hi @lazosweb,

How do you plan on storing the token?

lazosweb commented 4 years ago

Hi @stevebauman

The tymondesigns/jwt-auth package is responsible for that, it is not stored in the database or whatsoever. But in order to generate the token I need to implement the JWTSubject contract.

Below a sample using the DatabaseUserProvider... But because this is a Lumen API and I do not want to create a database to just add the users I want to get the token directly from the Active Directory using the NoDatabaseUserProvider.


class ApiUser extends Model implements AuthenticatableContract, AuthorizableContract, JWTSubject
{
    use Authenticatable, Authorizable, HasLdapUser;

    /**
     * Get the identifier that will be stored in the subject claim of the JWT.
     *
     * @return mixed
     `*/`
    public function getJWTIdentifier()
    {
        return $this->getKey();
    }

    /**
     * Return a key value array, containing any custom claims to be added to the JWT.
     *
     * @return array
     */
    public function getJWTCustomClaims()
    {
        return [];
    }
}
HarllanAndrye commented 3 years ago

What the solution? I'm with the same problem.

I'm try to use ldap + jwt, but the error is returned:

TypeError: Tymon\JWTAuth\JWT::fromUser(): Argument #1 ($user) must be of type Tymon\JWTAuth\Contracts\JWTSubject, Adldap\Models\User given, 
called in ...\vendor\tymon\jwt-auth\src\JWTAuth.php on line 55 
in file ...\vendor\tymon\jwt-auth\src\JWT.php on line 88
lazosweb commented 3 years ago

Not really. I just used the above.