Couchbase C Client
3.3.14
Asynchronous C Client for Couchbase
|
The lcb_AUTHENTICATOR object is how the library stores credentials internally, and may be used in cases where you'd like to manage credentials in an object separate from the library. This interface also provides better clarification between 'old style' (Classic) and new style (RBAC) auth.
If you don't have a specific need to have credentials managed in their own. lcb_create_st3::username and lcb_create_st3::passwd fields (note that username
is only valid on clusters 5.0 and higher):
If you are connecting to a cluster older than 5.0 and would like to issue N1QL queries against multiple password-protected buckets, you can use the LCB_CNTL_BUCKET_CRED setting to "add" more bucket:password pairs to the library. The library will then send these credentials whenever you issue a query with the LCB_CMD_F_MULTIAUTH flag set.
Or if you have a JSON encoder handy (or are interfacing from a higher level language) you can use the lcb_cntl_string() variant:
The json functions in the above example are mockups of however you would actually create a JSON array.
lcb_AUTHENTICATOR * lcbauth_new | ( | void | ) |
Creates a new authenticator object. You may destroy it using lcbauth_unref(). The returned object initially has a refcount of 1.
You must set the mode on this object before adding credentials to it. See lcbauth_set_mode().
Once you have added all the credentials to the object, you may assign it (or a copy, see lcbauth_clone()) to a library handle via lcb_set_auth().
Setting RBAC Auth:
Setting multi-bucket classic auth, also with cluster administrative credentials:
lcb_STATUS lcbauth_add_pass | ( | lcb_AUTHENTICATOR * | auth, |
const char * | user, | ||
const char * | pass, | ||
int | flags ) |
Add a set of credentials
auth | |
user | the username (or bucketname, if LCBAUTH_F_BUCKET is passed) |
pass | the password. If the password is NULL, the credential is removed |
flags | one of LCBAUTH_F_CLUSTER or LCBAUTH_F_BUCKET. If both flags are combined then the credential will be used for both bucket-level and cluster-level administrative operations (using LCB_HTTP_TYPE_MANAGEMENT). |
void lcbauth_ref | ( | lcb_AUTHENTICATOR * | auth | ) |
Increments the refcount on the authenticator object
auth |
The only time you would want to call this function is when sharing a single lcb_AUTHENTICATOR with multiple lcb_INSTANCE instances. While doing so is theoretically possible, it is not supported or tested.
void lcbauth_unref | ( | lcb_AUTHENTICATOR * | auth | ) |
Decrements the refcount on the authenticator object, freeing it if there are no more owners.
auth |
lcb_AUTHENTICATOR * lcbauth_clone | ( | const lcb_AUTHENTICATOR * | src | ) |
Makes a copy of an existing lcb_AUTHENTICATOR object. The returned authenticator object has a reference count of 1.
src | the authenticator object to clone |
This function is useful when you wish to copy an existing set of credentials for use with a new client.
lcb_STATUS lcbauth_set_mode | ( | lcb_AUTHENTICATOR * | src, |
lcbauth_MODE | mode ) |
Set the mode of this authenticator.
src | the authenticator |
mode | the mode to use. |
class lcb_AUTHENTICATOR |
Opaque pointer containing credentials for the library.
enum lcbauth_ADDPASSFLAGS |
Flags to use when adding a new set of credentials to lcbauth_add_pass.
enum lcbauth_RESULT |
Result could be used to notify the library that credentials cannot be resolved (e.g.
3rd party provider is not available)
enum lcbauth_MODE |
Enumerator | |
---|---|
LCBAUTH_MODE_CLASSIC | Use "bucket-specific" credentials when authenticating. This is the only way of authenticating up to server version 5.0 |
LCBAUTH_MODE_RBAC | Use role-based access control. This allows the same user to have access to multiple buckets with a single set of credentials. Note that if this option is selected, it becomes impossible to use LCBAUTH_F_BUCKET with lcbauth_add_pass() |