3

Is there any documentation or sample implementation of how an API can acquire token from another API that has Azure AD protection?

I tried to look for some working stuff but couldn't find one.

1 Answer 1

2

The most up to date way is using the Azure.Identity package. It's also the package that most Azure C# SDK's are using for authentication as of this moment. Depending on the way you want to authenticate you'll need to pick the appropriate credential class and then it's as simple as calling the method for obtaining the token.

//example of the client credential flow
var cred = new ClientSecretCredential(
    tenantId: "00000000-0000-0000-0000-000000000000",
    clientId: "00000000-0000-0000-0000-000000000000",
    clientSecret: "<your secret>");
//acquiring a token (call this every time you need a token to avoid expiration)
var token = await cred.GetTokenAsync(new TokenRequestContext(new[] { "00000000-0000-0000-0000-000000000000/.default" }));
Sign up to request clarification or add additional context in comments.

1 Comment

Awesome! didnt find this in my search. but will try this one. Thank you!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.