MCPcopy Create free account
hub / github.com/Snapchat/KeyDB / authenticateClientWithUser

Function authenticateClientWithUser

src/module.cpp:6734–6760  ·  view source on GitHub ↗

Authenticate the client associated with the context with * the provided user. Returns REDISMODULE_OK on success and * REDISMODULE_ERR on error. * * This authentication can be tracked with the optional callback and private * data fields. The callback will be called whenever the user of the client * changes. This callback should be used to cleanup any state that is being * kept in the modul

Source from the content-addressed store, hash-verified

6732 * client and do the authentication in the background and then attach the user
6733 * to the client in a threadsafe context. */
6734static int authenticateClientWithUser(RedisModuleCtx *ctx, user *user, RedisModuleUserChangedFunc callback, void *privdata, uint64_t *client_id) {
6735 if (user->flags & USER_FLAG_DISABLED) {
6736 return REDISMODULE_ERR;
6737 }
6738
6739 /* Avoid settings which are meaningless and will be lost */
6740 if (!ctx->client || (ctx->client->flags & CLIENT_MODULE)) {
6741 return REDISMODULE_ERR;
6742 }
6743
6744 moduleNotifyUserChanged(ctx->client);
6745
6746 ctx->client->user = user;
6747 ctx->client->authenticated = 1;
6748
6749 if (callback) {
6750 ctx->client->auth_callback = callback;
6751 ctx->client->auth_callback_privdata = privdata;
6752 ctx->client->auth_module = ctx->module;
6753 }
6754
6755 if (client_id) {
6756 *client_id = ctx->client->id;
6757 }
6758
6759 return REDISMODULE_OK;
6760}
6761
6762
6763/* Authenticate the current context's user with the provided redis acl user.

Callers 2

Calls 1

moduleNotifyUserChangedFunction · 0.85

Tested by

no test coverage detected