Skip to content
This repository has been archived by the owner on Jan 23, 2023. It is now read-only.
/ corefx Public archive

Azure Active Directory Authentication using Access Token #30342

Merged
merged 7 commits into from
Jun 26, 2018

Conversation

AfsanehR-zz
Copy link
Contributor

@AfsanehR-zz AfsanehR-zz commented Jun 12, 2018

Fixes #13660 This pull request will enable authentication using only Access Token.

{
CheckAndThrowOnInvalidCombinationOfConnectionStringAndSqlCredential(connectionOptions);
}
else if (_accessToken != null)
Copy link
Member

Choose a reason for hiding this comment

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

Looks like this could just be:

else // _accessToken != null

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done.

{
result = null;
}
return result;
Copy link
Member

Choose a reason for hiding this comment

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

Nit: kind of a strange construction... seems like it could just be:

return InnerConnection.ShouldHidePassword && connectionOptions != null && !connectionOptions.PersistSecurityInfo ?
    null :
    _accessToken;

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done.

}

_accessToken = value;
// Need to call ConnectionString_Set to do proper pool group check
Copy link
Member

Choose a reason for hiding this comment

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

Does ConnectionString_Set throw? If it does, is it weird that we would have already then stored the value into _accessToken?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done.

internal bool _fedAuthRequired;
internal bool _federatedAuthenticationRequested;
internal bool _federatedAuthenticationAcknowledged;
internal byte[] _accessTokenInBytes;
Copy link
Member

Choose a reason for hiding this comment

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

Can any of these be made readonly?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We can't make them readonly. They are being set somewhere else in the code and would cause this issue:
A readonly field cannot be used as a ref or out value

_physicalStateObj.WriteByteArray(fedAuthFeatureData.accessToken, fedAuthFeatureData.accessToken.Length, 0);
break;
default:
Debug.Assert(false, "Unrecognized FedAuthLibrary type for feature extension request");
Copy link
Member

Choose a reason for hiding this comment

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

Debug.Fail

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done.


switch (_fedAuthFeatureExtensionData.Value.libraryType)
{
case TdsEnums.FedAuthLibrary.ADAL: // For later support
Copy link
Contributor

Choose a reason for hiding this comment

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

Is the server, ever expected to send TdsEnums.FedAuthLibrary.ADAL for AccessToken?

// only add lengths of password and username if not using SSPI
if (!rec.useSSPI)
// only add lengths of password and username if not using SSPI or requesting federated authentication info
if (!rec.useSSPI && !(_connHandler._federatedAuthenticationRequested))
Copy link
Contributor

@saurabh500 saurabh500 Jun 22, 2018

Choose a reason for hiding this comment

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

Nit: unnecessary parentheses around _connHandler._federatedAuthenticationRequested

Copy link
Contributor

@saurabh500 saurabh500 left a comment

Choose a reason for hiding this comment

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

@afsanehr The changes look good over all. How was this tested? How were the access tokens generated and passed to the server?

SqlConnectionStringBuilder _builder;

[Fact]
public void InvalidCombinationOfAccessToken()
Copy link
Contributor

Choose a reason for hiding this comment

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

This test can be parameterized by passing different connection strings, perhaps by using [Theory] and [InlineData] attribute.

@AfsanehR-zz
Copy link
Contributor Author

@dotnet-bot test NETFX x86 Release Build

@AfsanehR-zz AfsanehR-zz merged commit a74bf42 into dotnet:master Jun 26, 2018
@karelz karelz added this to the 3.0 milestone Jul 8, 2018
picenka21 pushed a commit to picenka21/runtime that referenced this pull request Feb 18, 2022
Azure Active Directory Authentication using Access Token

Commit migrated from dotnet/corefx@a74bf42
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants