🎄 Happy Holidays! 🥳
Most of Solace is closed December 24–January 1 so our employees can spend time with their families. We will re-open Thursday, January 2, 2024. Please expect slower response times during this period and open a support ticket for anything needing immediate assistance.
Happy Holidays!
Please note: most of Solace is closed December 25–January 2, and will re-open Tuesday, January 3, 2023.
Need a Solace example demonstrating how to use OAUTH using C++ Solace API.
I did go through the Solace Doc for C++ API but didn't find any Sample example explaining house to use Solace C++ API to enable OAuth Authentication.
Is there any Sample code available? Can anyone please guide.
Answers
-
Hey @TestSolace - have you checked this blog for Oauth configuration https://solace.com/blog/connect-pubsub-smf-with-oauth-openid-connect/? it shows a JCSMP sample but I would guess you can take a similar approach with C++. I'll take a look at the C API docs and see if I can point you to a particular location.
And keep us posted here as well if you were able to configure and run it :)
0 -
Hi @TestSolace
Just to add to Tamimi's answer, depending on how the client would be authenticated it can use Access token or ID token. One of these properties must be set for the session properties structure and passed to the session when creating the session.
Information for these parameters definitions can be found here:
https://docs.solace.com/API-Developer-Online-Ref-Documentation/c/index.html
A sample code how to set the session properties can be found here (see sessionProps variable):
https://tutorials.solace.dev/c/publish-subscribe/
Code repo example https://github.com/SolaceSamples/solace-samples-c/blob/master/src/intro/QueuePublisher.c (line 150 on)
I hope this helps.
1 -
Hey @TestSolace - just confirming if this answers your question or not?
0 -
Hi @Tamimi ,
Yes, i have got the Solace APIS to be able to use OAuth authentication.
Can you please provide any suggestion how can we pass the OAuth token . I am sure that i don't want to hard code it. But did you get any coding sample in C++ that shows how the token to be used is passed in OAuth Solace.
0 -
Hi @TestSolace,
See my comment with the example link. You need to set the sessionProps for an Access Token or Client ID token.
These are defined as Session Configuration Properties definitions (SolClient -> modules -> Session Configuration Properties):
https://docs.solace.com/API-Developer-Online-Ref-Documentation/c/index.html
#define SOLCLIENT_SESSION_PROP_OAUTH2_ACCESS_TOKEN "SESSION_OAUTH2_ACCESS_TOKEN" The OAUTH2 access token.
#define SOLCLIENT_SESSION_PROP_OAUTH2_ISSUER_IDENTIFIER "SESSION_OAUTH2_ISSUER_IDENTIFIER" The optional Issuer identifier URI for OAUTH2 access token based authentication.
#define SOLCLIENT_SESSION_PROP_OIDC_ID_TOKEN "SESSION_OIDC_ID_TOKEN" The OIDC (OpenId Connect) ID Token.
Depending on your OAuth flow type, you may choose to:
a) pass the OAuth token as a parameter to your code and then set it in the sessionProps before you create a session (usually for Client ID token, as it doesn't change often)
b) fetch the token (usually for Access Token, as it is short-lived) from your OAuth provider before it expires and create a new session with the new token value.
I have not seen such exact sample for the C API, but the OAuth parameters should be set similar to how username, password , or any other session property is set.
1