MONGOC_OIDC_CALLBACK_T(3)

πŸ“¦
version 2.5.6 Β· 3 versions
, in epel 10

Okay bestie, this is the libmongoc page for MONGOC_OIDC_CALLBACK_T(3) β€” aka the mongoc_oidc_callback_t page. Buckle up, it’s OIDC callback time. πŸ’…βœ¨

✨ SYNOPSIS ✨

          typedef struct _mongoc_oidc_callback_t mongoc_oidc_callback_t;

Okay so mongoc_oidc_callback_t represents a user-defined callback function, mongoc_oidc_callback_fn_t, that returns an OIDC access token. Literally that’s the whole vibe. 🫢

This callback is your go-to when you need to integrate with OIDC providers that are not supported by the built-in provider integrations (the manual points at Authentication Mechanism Properties). No cap, it’s the custom-hookup route.

πŸ¦‹ LIFECYCLE πŸ¦‹

Here’s the important part, bestie: the function and optional user data stored by mongoc_oidc_callback_t must outlive any associated client or client pool object which may invoke the stored callback function.

⚠️ Translation: do not let that callback or its user data vibe-check out early. It has to stick around longer than any client or client pool that might call it. πŸ’€

πŸ’… THREAD SAFETY πŸ’…

Okay, thread-safety tea time. The callback function stored by a mongoc_oidc_callback_t object will be invoked by at most one thread at a time for an associated mongoc_client_t or mongoc_client_pool_t object:

          static mongoc_oidc_credential_t *
          single_thread_only (mongoc_oidc_callback_params_t *params)
          {
             // This function does not need to support invocation by more than thread at a time.

             // ...
          }

          void
          with_single_client (void)
          {
             mongoc_client_t *client = /* ... */;

             {
                mongoc_oidc_callback_t *callback = mongoc_oidc_callback_new (&single_thread_only);
                BSON_ASSERT (mongoc_client_set_oidc_callback (client, callback));
                mongoc_oidc_callback_destroy (callback);
             }

             // ... client operations ...

             mongoc_client_destroy (client);
          }

          void
          with_single_pool (void)
          {
             mongoc_client_pool_t *pool = /* ... */;

             {
                mongoc_oidc_callback_t *callback = mongoc_oidc_callback_new (&single_thread_only);
                BSON_ASSERT (mongoc_client_pool_set_oidc_callback (pool, callback));
                mongoc_oidc_callback_destroy (callback);
             }

             // ... client pool operations ...

             mongoc_client_pool_destroy (pool);
          }

But listen: if the callback is associated with more than one mongoc_client_t object (in multiple threads), or with more than one mongoc_client_pool_t object (even in a single thread), the callback function MUST support invocation by more than one thread at a time:

          static mongoc_oidc_credential_t *
          many_threads_possible (mongoc_oidc_callback_params_t *params)
          {
             // This function MUST support invocation by more than one thread at a time.

             // ...
          }

          void
          with_many_clients (void)
          {
             mongoc_client_t *client_a = /* ... */;
             mongoc_client_t *client_b = /* ... */;

             {
                mongoc_oidc_callback_t *callback = mongoc_oidc_callback_new (&many_threads_possible);
                BSON_ASSERT (mongoc_client_set_oidc_callback (client_a, callback));
                BSON_ASSERT (mongoc_client_set_oidc_callback (client_b, callback));
                mongoc_oidc_callback_destroy (callback);
             }

             pthread_t thread_a;
             pthread_t thread_b;

             if (pthread_create (&thread_a, NULL, /* thread_a_fn */, client_a) != 0) { /* ... */ }
             if (pthread_create (&thread_b, NULL, /* thread_b_fn */, client_b) != 0) { /* ... */ }

             // ... client operations using multiple threads ...

             if (pthread_join (&thread_a, NULL) != 0) { /* ... */ }
             if (pthread_join (&thread_b, NULL) != 0) { /* ... */ }

             mongoc_client_destroy (client_a);
             mongoc_client_destroy (client_b);
          }

          void
          with_many_pools (void)
          {
             mongoc_client_pool_t *pool_a = /* ... */;
             mongoc_client_pool_t *pool_b = /* ... */;

             {
                mongoc_oidc_callback_t *callback = mongoc_oidc_callback_new (&many_threads_possible);
                BSON_ASSERT (mongoc_client_pool_set_oidc_callback (pool_a, callback));
                BSON_ASSERT (mongoc_client_pool_set_oidc_callback (pool_b, callback));
                mongoc_oidc_callback_destroy (callback);
             }

             // ... client operations using multiple client pools ...

             mongoc_client_pool_destroy (pool_a);
             mongoc_client_pool_destroy (pool_b);
          }

πŸ‘€ SEE ALSO πŸ‘€

  • mongoc_client_t
  • mongoc_client_pool_t
  • mongoc_oidc_callback_fn_t
  • mongoc_oidc_callback_params_t
  • mongoc_oidc_credential_t

🌸 AUTHOR 🌸

MongoDB, Inc

2009-present, MongoDB, Inc.


πŸ’– That’s the whole page, bestie. This is from libmongoc version 2.5.6, dated Oct 09, 2026 β€” now go be the main character of your OIDC callback setup. πŸ’…βœ¨
πŸ“¦ where this page comes from