Skip to content
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

Add AAD support #746

Merged
merged 29 commits into from
May 24, 2021
Merged

Add AAD support #746

merged 29 commits into from
May 24, 2021

Conversation

hectorhdzg
Copy link
Member

No description provided.

@kryalama

This comment has been minimized.

@TimothyMothra
Copy link
Member

I think we are leaning away from including those values in the Connection String.

@hectorhdzg hectorhdzg marked this pull request as ready for review March 30, 2021 23:37
@hectorhdzg hectorhdzg requested a review from MSNev March 30, 2021 23:38
*/
public async addAuthorizationHeader(requestOptions: http.RequestOptions | https.RequestOptions): Promise<void> {
const token = await this._getToken({});
requestOptions.headers[azureCore.Constants.HeaderConstants.AUTHORIZATION] = `Bearer ${token}`;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does the header value need to be encoded?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the way other SDKs are adding the header, code is not ready on Breeze side so this may change in the future

// after that point, we retry the refresh of the token only if the token refresher is ready.
let token = this._tokenCache.getCachedToken();
if (!token && this._tokenRefresher.isReady()) {
token = await this._tokenRefresher.refresh(options);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What happens if this fails, does the setCachedToken() handle null / undefined or invalid token value?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The token could be null or undefined, will add the check before adding the header

https://github.com/Azure/azure-sdk-for-js/blob/master/sdk/core/core-http/src/credentials/accessTokenCache.ts#L50

Library/AuthHandler.ts Outdated Show resolved Hide resolved
Library/AuthHandler.ts Outdated Show resolved Hide resolved
// after that point, we retry the refresh of the token only if the token refresher is ready.
let token = this._tokenCache.getCachedToken();
if (!token && this._tokenRefresher.isReady()) {
token = await this._tokenRefresher.refresh(options);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1

Library/Config.ts Outdated Show resolved Hide resolved
Library/AuthHandler.ts Outdated Show resolved Hide resolved
Library/QuickPulseSender.ts Outdated Show resolved Hide resolved
Library/QuickPulseSender.ts Outdated Show resolved Hide resolved
@@ -146,6 +165,8 @@ class Sender {
}
// store to disk in case of burst throttling
} else if (
res.statusCode === 401 || // Unauthorized
res.statusCode === 403 || // Forbidden
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So there is no retry when we hit any AAD auth error? Is that what other langs are doing? I thought we were going to retry!

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This specific code is the retry logic, envelopes would be put into disk, are you expecting something else?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, just looked at Python PR. Leighton is retrying if we hit 401. @lzchen can you comment?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes 401 is a retry scenario.

Removing CS options
Adding config in readme
Declarations/Contracts/Constants.ts Outdated Show resolved Hide resolved
Library/AuthorizationHandler.ts Outdated Show resolved Hide resolved
const applicationInsightsResource = "https://monitor.azure.com";


class AuthorizationHandler {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be private?

// Add bearer token
await authHandler.addAuthorizationHeader(options);
}
catch (authError) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe we want to do different things (retry, drop, etc.) based off the type of exception that is thrown when getting the token. Python throws these types of exceptions (I believe Java is similar). For CredentialUnavailableError we probably do not want to retry. For ClientAuthenticationError we should investigate which cases make sense to retry.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we do not retry telemetry will be lost on the spot in that case, even if customer configuration is wrong we should try to store the telemetry in disk, what about AAD outages, maybe CredentialUnavailableError is triggered in that case?

@lzchen
Copy link

lzchen commented Apr 7, 2021

I think an example file of passing in a TokenCredential would be good.

Library/Sender.ts Outdated Show resolved Hide resolved
@hectorhdzg hectorhdzg merged commit 4f60072 into develop May 24, 2021
@hectorhdzg hectorhdzg deleted the hectorhdzg/aad branch June 2, 2021 00:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants