Giter Club home page Giter Club logo

auth's People

Contributors

korsvanloon avatar thosakwe avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

auth's Issues

Best scope handler

Hi all, please can you explain me what is the best way to handle user auth and manage her scope authorizations?

For example now I've this situation:

I create a plugin like this to handle login

Future<void> configureServer(Angel app) async {
  // Inizializzazione Authenticator
  var auth = AngelAuth<User>(jwtKey: app.configuration["jwt_secret"] as String, secureCookies: app.environment.isProduction);
  auth.serializer = (u) => u.id;
  auth.deserializer = (id) => _fetchUserById(id, app);
  await app.configure(auth.configureServer);

  auth.strategies['local'] = LocalAuthStrategy((username, password) async {
    var executor = app.container.make<QueryExecutor>();
    // Cerco l'Utente
    var query = UserQuery();
    query.where..username.equals(username);
    var user = await query.getOne(executor);
    if (user != null) {
      if (Password.verify(password, user.hashedPassword)) {
        return user;
      }
    }

    throw AngelHttpException.notAuthenticated();
  });

  // ROUTER - Login
  app.post('/auth/login', auth.authenticate('local'));
}

Future<User> _fetchUserById(id, Angel app) async {
  if (id is String) {
    var executor = app.container.make<QueryExecutor>();
    // Cerco l'Utente
    var query = UserQuery();
    query.where..id.equals(int.tryParse(id));
    var user = await query.getOne(executor);
    if (user != null) {
      return user;
    }
  }
  throw AngelHttpException.notAuthenticated();
}

Now what is the best way to manage the user authorization?

Export middleware as functions

const RequireAuthorizationMiddleware forceAuth = const RequireAuthorizationMiddleware();

RequestMiddleware forceAuthBasic({String realm}) {
  return (req, res) async {...};
}

Deprecate auth.decodeJwt in favor of asynchronous dependency injection

Users will only have to call configureServer, instead of also mounting decodeJwt.

// In configureServer, where `_decodeJwt` returns `Future<User>`.
app.container.registerLazySingleton<Future<User>>((container) async {
  var req = container.make<RequestContext>();
  var res = container.make<ResponseContext>();
  return await _decodeJwt(req, res);
});

// Asynchronously parse the JWT, if it exists.
var user = await req.container.makeAsync<User>();

Add callback to options

This would be run instead of redirects if present

new AngelAuthOptions(callback: (req, res, token) async {
  return token.toJson();
})

This would be nice for things like auth_google, and wouldn't force you into using cookies

How to acquire authentication's information?

After authenticated how can I get the authentication's information in any routes?
Like,

app.post('/login',auth.authenticate('local'));
app.get('/user', (req, res){...});

how can I get authentication's information out of req?
According to the example, I don't quite get the concept of ioc function and it doesn't seem to work in action anyway.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.