-
Notifications
You must be signed in to change notification settings - Fork 2
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
EventHubTokenCredential
is not publicly exported from lib
#10
Comments
I will probably change the version number to follow that of |
@jackgerrits I have something (not published on crates.io yet) that already works with // rust
use azure_identity::DefaultAzureCredential;
use azure_core::auth::TokenCredential;
const DEFAULT_SCOPE: &str = "https://eventhubs.azure.net/.default";
#[tokio::main]
async fn main() {
println!("Hello, world!");
let credential = DefaultAzureCredential::default();
let token = credential.get_token(DEFAULT_SCOPE).await.unwrap();
} Then I tried the same thing but with dotnet sdk (the code snippet can be found below), and everything just works fine. // dotnet
using Azure.Core;
using Azure.Identity;
var credential = new DefaultAzureCredential();
var context = new TokenRequestContext(new[] {"https://eventhubs.azure.net/.default"});
var accessToken = credential.GetToken(context);
String accessTokenString = accessToken.Token.ToString();
Console.WriteLine(accessTokenString); This could very likely be my fault as I am not super familiar with managed identity on azure, but I wonder if there's bug with |
I will make a preview release on crates.io so that you can give it a try |
Hi @jackgerrits I have made a preview release ("0.14.0-alpha") on crates.io. I want to make sure that |
There seems to be a long queue on docs.rs. I will just list some example showcasing how to work with credentials in this preview release.
// You can turn `AzureNamedKeyCredential` or `AzureSasCredential` into
// `EventHubTokenCredential` and then use
// `EventHubConnection::from_namespace_and_credential`
let named_key_credential = AzureNamedKeyCredential::new(key_name, key);
// `AzureSasCredential` doesn't need the signature authorization resource
let resource = build_connection_signature_authorization_resource(transport_type, &fully_qualified_namespace, &event_hub_name).unwrap();
let shared_access_credential = SharedAccessCredential::try_from_named_key_credential(credential, resource).unwrap();
let connection = EventHubConnection::from_namespace_and_credential(
fully_qualified_namespace,
event_hub_name,
shared_access_credential,
EventHubConnectionOptions::default(),
).await.unwrap();
// Or you can use the convenience function
let named_key_credential = AzureNamedKeyCredential::new(key_name, key);
let connection = EventHubConnection::from_namespace_and_named_key_credential(
fully_qualified_namespace,
event_hub_name,
named_key_credential,
options,
).await.unwrap();
// `azure_identity::DefaultAzureCredential` implements `azure_core::TokenCredential`
let credential = azure_identity::DefaultAzureCredential::default();
let connection = EventHubConnection::from_namespace_and_credential(
fully_qualified_namespace,
event_hub_name,
credential,
EventHubConnectionOptions::default(),
).await.unwrap(); |
Thanks! I will try it out. |
@minghuaw const DEFAULT_SCOPE: &str = "https://eventhubs.azure.net/"; This seems to be documented here: https://learn.microsoft.com/en-us/azure/event-hubs/authenticate-application However, I am a bit confused because the scope you originally used also seems to be used often if you search for it on GitHub. |
Thanks for the information. That indeed worked. But the original |
It seems like |
It looks like the resource is Looking at the insides of the identity module for CLI credentials it is passing the parameter that is passed through to This would indicate that the resource and not scope should be used.
It seems like it is using AAD 1.0, and hence the reason why the ![]() |
I think I figured out why it didn't work. https://github.com/Azure/azure-sdk-for-rust/blob/c0d938c7ae0f5fef878956617ff73245e94026a9/sdk/identity/src/token_credentials/client_secret_credentials.rs#L144 |
Ah that makes sense, great! |
@jackgerrits The problem with |
Thank you! |
I will leave this issue open for now. Feel free to close it if the new version works as expected for you :) |
Hi @jackgerrits , I opened another issue #13 which discusses whether methods like |
It looks like the default credential is working well now, thank you! (I replied to that in the other issue) |
EventHubTokenCredential
is not accessible due to the module containing it not being publicly exported from the library.It is public here: https://github.com/minghuaw/azure-sdk-for-rust/blob/de21c92e74c99d7b4cb4afbde6d1703a3f4aeb46/sdk/messaging_eventhubs/src/authorization/event_hub_token_credential.rs#L7C6-L7C6
But it is not reexported in
lib.rs
The variants of the enum also should be exported so they can be used by a consumer.
The text was updated successfully, but these errors were encountered: