dox_auth 2.0.0-alpha.2 copy "dox_auth: ^2.0.0-alpha.2" to clipboard
dox_auth: ^2.0.0-alpha.2 copied to clipboard

Authentication package for dox framework with jsonwebtoken(jwt) driver.

Dox Auth #

Dox Auth is an authentication package for dox framework. Currently it support JWT driver and support only with Dox Query Builder(ORM)

Usage #

  1. Create auth config
import 'package:dox_auth/dox_auth.dart';
import 'package:dox_core/dox_core.dart';
import 'package:dox/models/user/user.model.dart';

class AuthConfig extends AuthConfigInterface {
  @override
  String get defaultGuard => 'web';

  @override
  Map<String, Guard> get guards => <String, Guard>{
        'web': Guard(
          driver: JwtDriver(
            secret: SecretKey(Env.get('APP_KEY')),
          ),
          provider: Provider(
            model: () => User(),
          ),
        ),
      };
}
  1. Modify bin/server.dart to add auth config
Dox dox = Dox();
await dox.initialize(config);
dox.setAuthConfig(AuthConfig());
  1. Attempt Login
Map<String, dynamic> credentials = req.only(<String>['email', 'password']);

Auth auth = Auth();
String? token = await auth.attempt(credentials);
User? user = auth.user<User>();
  1. Register doxAuthMiddleware in route
 Route.get('/auth/user', <dynamic>[doxAuthMiddleware, authController.user]);
  1. Verify Logged In or Fetch User information
Future<dynamic> fetchUser(DoxRequest req) async {
  Auth? auth = req.auth<Auth>();
  if (auth?.isLoggedIn() == true) {
    return auth?.user();
  }
  throw UnAuthorizedException();
}

Expired In #

JwtDriver(
  secret: SecretKey(Env.get('APP_KEY')),
  expiresIn: Duration(hours: 5),
),

Issuer #

JwtDriver(
  secret: SecretKey(Env.get('APP_KEY')),
  issuer: 'https://dartondox.dev',
),

Algorithm #

JwtDriver(
  secret: SecretKey(Env.get('APP_KEY')),
  algorithm: JWTAlgorithm.HS256,
),

for more information about algorithm please visit dart jsonwebstoken

Documentation #

For detailed information about the framework and its functionalities, refer to the Dox Documentation.

Security Vulnerabilities #

Dox take the security of our framework seriously. If you identify any security vulnerabilities in our application, please notify us immediately by sending an email to support@dartondox.dev. We appreciate your responsible disclosure and will respond promptly to address and resolve any identified security issues. Your cooperation helps us maintain the integrity and safety of our software for all users.

Contributing #

We welcome contributions from the community! If you'd like to contribute to the Dox Auth, please fork the repo and PR to us.

License #

This project is licensed under the MIT License.

Community #

1
likes
0
pub points
0%
popularity

Publisher

verified publisherdartondox.dev

Authentication package for dox framework with jsonwebtoken(jwt) driver.

Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

bcrypt, dart_jsonwebtoken, dox_annotation, dox_query_builder

More

Packages that depend on dox_auth