-
Notifications
You must be signed in to change notification settings - Fork 934
Added example with oauth/oidc example with CCloud logicalCluster and identityPoolId #1593
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from 1 commit
18a5faf
bf66410
5223cd2
cddd40d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -29,36 +29,29 @@ | |
| import requests | ||
|
|
||
|
|
||
| def _get_token(args, config): | ||
| """Note here value of config comes from sasl.oauthbearer.config below. | ||
| It is not used in this example but you can put arbitrary values to | ||
| configure how you can get the token (e.g. which token URL to use) | ||
| """ | ||
| payload = { | ||
| 'grant_type': 'client_credentials', | ||
| 'scope': ' '.join(args.scopes) | ||
| } | ||
| resp = requests.post(args.token_url, | ||
| auth=(args.client_id, args.client_secret), | ||
| data=payload) | ||
| token = resp.json() | ||
| return token['access_token'], time.time() + float(token['expires_in']) | ||
|
|
||
|
|
||
| def producer_config(args): | ||
| logger = logging.getLogger(__name__) | ||
| return { | ||
| logger.setLevel(logging.DEBUG) | ||
| params = { | ||
| 'bootstrap.servers': args.bootstrap_servers, | ||
| 'security.protocol': 'sasl_plaintext', | ||
| 'retries': 1, | ||
| 'message.send.max.retries': 1, | ||
sarwarbhuiyan marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| 'delivery.timeout.ms': 30000, | ||
sarwarbhuiyan marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| 'security.protocol': 'SASL_SSL', | ||
| 'sasl.mechanisms': 'OAUTHBEARER', | ||
| # sasl.oauthbearer.config can be used to pass argument to your oauth_cb | ||
| # It is not used in this example since we are passing all the arguments | ||
| # from command line | ||
| # 'sasl.oauthbearer.config': 'not-used', | ||
| 'oauth_cb': functools.partial(_get_token, args), | ||
| 'logger': logger, | ||
| 'sasl.oauthbearer.method': 'oidc', | ||
| 'sasl.oauthbearer.client.id': args.client_id, | ||
| 'sasl.oauthbearer.client.secret': args.client_secret, | ||
| 'sasl.oauthbearer.token.endpoint.url': args.token_url, | ||
| 'sasl.oauthbearer.scope': ' '.join(args.scopes) | ||
| } | ||
| if args.logical_cluster and args.identity_pool_id: | ||
| params['sasl.oauthbearer.extensions'] = 'logicalCluster='+args.logical_cluster+',identityPoolId='+args.identity_pool_id | ||
|
|
||
| if args.debug: | ||
| params['debug'] = args.debug | ||
|
|
||
| return params | ||
|
|
||
| def delivery_report(err, msg): | ||
| """ | ||
|
|
@@ -131,5 +124,8 @@ def main(args): | |
| help="Token URL.") | ||
| parser.add_argument('--scopes', dest="scopes", required=True, nargs='+', | ||
| help="Scopes requested from OAuth server.") | ||
|
|
||
| parser.add_argument('--logical-cluster', dest="logical_cluster", required=False, help="Logical Cluster.") | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If we move this to CC specific example, does it make sense to mark these are required?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The original example is using an outdated callback based method so this example applies there too. Also, since the only difference between CC and AK/CP is this one param, it doesn't make sense to split it into another file. There's a wider task of updating all the examples to be using the recommended approach. The purpose of examples is to educate.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We can improve old example as well and create a new example to cater mainly CC usecase. The idea is to make it easy for non CC user to use SASL as well. With everything specific to CC, user might get confused.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's not just specific to CC though. If you don't include the logicalClusterId and identityPoolId in the cli params, it's just just works against any AK or CP.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I just don't want code that'll be copy pasted for a 2 line difference. The cli works with both CP and CC. |
||
| parser.add_argument('--identity-pool-id', dest="identity_pool_id", required=False, help="Identity Pool ID.") | ||
| parser.add_argument('--debug', dest="debug", required=False, help="Comma separated list of following values broker,topic,msg") | ||
sarwarbhuiyan marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| main(parser.parse_args()) | ||
Uh oh!
There was an error while loading. Please reload this page.