- How do I install marvin255/jwt in Laravel?
- Install it with Composer using composer require marvin255/jwt. In Laravel, the package follows conventions with a service provider and configuration for the secret, signing algorithm, and TTL. After installation, set your JWT configuration values and start generating or validating tokens.
- What is marvin255/jwt used for?
- It is used to issue, sign, and validate JSON Web Tokens in Laravel and plain PHP applications. Typical use cases are stateless authentication, API access tokens, and secure data exchange between services. It keeps the core framework-agnostic while adding Laravel-friendly configuration, service provider integration, and middleware.
- How do I generate a JWT token with marvin255/jwt?
- Use the package's fluent token generation API to create and sign a JWT. You configure the signing algorithm, secret, and TTL first, then generate the token with the claims your application needs. The result is a signed token string you can return to a client or include in a request.
- How do I validate a JWT token in Laravel with marvin255/jwt?
- Use the package verification helpers to decode and validate the token signature and claims. In Laravel you can also rely on the provided middleware to validate tokens before a route runs. Expired or invalid tokens raise clear exceptions, which you can catch and convert into the appropriate HTTP response.
- Does marvin255/jwt work outside Laravel?
- Yes. The core library is framework-agnostic and can be used in any PHP project via Composer. Laravel-specific features such as the service provider and middleware are optional conveniences. You can use the same token generation and validation API in plain PHP.
- How do I protect Laravel routes with marvin255/jwt middleware?
- Add the package middleware to the routes or route groups you want to protect. The middleware validates the JWT before the request reaches your controller and raises clear exceptions for expired or invalid tokens. Configure the secret, algorithm, and TTL so validation matches how the tokens were issued.
- How do I configure the JWT secret, algorithm, and TTL in marvin255/jwt?
- The package follows Laravel conventions, so you configure the secret, signing algorithm, and token lifetime in the package configuration. Keep secrets out of source control and use environment-specific values. Signing and verification use the same configuration so token handling stays consistent.
- What happens when a token is expired or invalid in marvin255/jwt?
- marvin255/jwt raises clear exceptions for expired or invalid tokens instead of returning ambiguous results. You should catch those exceptions in your application and return an appropriate response, such as HTTP 401 for authentication failures. This makes it easier to distinguish expired tokens from other validation errors.
- Can I use marvin255/jwt for stateless API authentication?
- Yes. The package is built for issuing and validating JWTs, which enables stateless authentication without server-side sessions. In Laravel you can combine token generation with the provided middleware to protect API routes. Configure a suitable TTL and secret for your environment.
- Is marvin255/jwt suitable for production use?
- marvin255/jwt is a lightweight library with configurable signing, TTL, and clear validation exceptions, which are the core pieces needed for JWT-based authentication. For production, use strong secrets, HTTPS, appropriate token lifetimes, and proper exception handling. Because the core is framework-agnostic and dependency-light, it can fit Laravel and plain PHP deployments.