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

Split authority #151

Merged
merged 58 commits into from
Sep 12, 2018
Merged

Split authority #151

merged 58 commits into from
Sep 12, 2018

Conversation

antrix1989
Copy link
Contributor

No description provided.

@antrix1989 antrix1989 force-pushed the sedemche/split_authorities branch from d34e91b to 12739ce Compare June 26, 2018 18:54
@antrix1989 antrix1989 changed the title Split authority [in progress] Split authority Jun 27, 2018
@antrix1989 antrix1989 changed the base branch from sedemche/aad_authority_nscache to dev June 28, 2018 21:31
@@ -9,13 +9,21 @@
/* Begin PBXBuildFile section */
04930F851FEC8E6800FC4DCD /* MSIDAadAuthorityCache.m in Sources */ = {isa = PBXBuildFile; fileRef = 04930F831FEC8E6800FC4DCD /* MSIDAadAuthorityCache.m */; };
04930F8B1FEC8EB900FC4DCD /* MSIDAadAuthorityCache.m in Sources */ = {isa = PBXBuildFile; fileRef = 04930F831FEC8E6800FC4DCD /* MSIDAadAuthorityCache.m */; };
04930F8C1FEC8EC200FC4DCD /* MSIDAadAuthorityCache+TestUtil.m in Sources */ = {isa = PBXBuildFile; fileRef = 04930F881FEC8E9400FC4DCD /* MSIDAadAuthorityCache+TestUtil.m */; };
04930F8D1FEC8EC200FC4DCD /* MSIDAadAuthorityCache+TestUtil.m in Sources */ = {isa = PBXBuildFile; fileRef = 04930F881FEC8E9400FC4DCD /* MSIDAadAuthorityCache+TestUtil.m */; };
04930F8C1FEC8EC200FC4DCD /* (null) in Sources */ = {isa = PBXBuildFile; };
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 some kind of a project file conflict (null). Can you check this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed


@property (nonatomic, nullable) NSString *aadAuthorityDiscoveryApiVersion;

@property (nonatomic, nullable) NSString *drsDiscoveryApiVersion;
Copy link
Member

Choose a reason for hiding this comment

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

When do we use DRS for AAD authority validation?

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 don't use it for AAD, it is for ADFS authority validation.

typedef NS_ENUM(NSInteger, MSIDADFSType)
{
MSIDADFSTypeOnPrems,
MSIDADFSTypeCloud
Copy link
Member

@oldalton oldalton Jun 28, 2018

Choose a reason for hiding this comment

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

Let's rename MSIDADFSTypeCloud to something more appropriate

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


typedef NS_ENUM(NSInteger, MSIDADFSType)
{
MSIDADFSTypeOnPrems,
Copy link
Member

Choose a reason for hiding this comment

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

nit: OnPrems -> OnPrem

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

account.authority = [MSIDAuthority cacheUrlForAuthority:refreshToken.authority tenantId:refreshToken.realm];

__auto_type authorityFactory = [MSIDAuthorityFactory new];
__auto_type authority = [authorityFactory authorityFromUrl:refreshToken.authority rawTenant:refreshToken.realm context:nil error:nil];
Copy link
Member

Choose a reason for hiding this comment

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

will this do authority aliasing?

{
if (!validate)
{
__auto_type openIdConfigurationEndpoint = [self openIdConfigurationEndpointForAuthority:authority.url];
Copy link
Member

Choose a reason for hiding this comment

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

Not all ADFS versions support openid

Copy link
Contributor Author

Choose a reason for hiding this comment

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

what should we do in such case? In current ADAL/MSAL we assume that adfs is always supports open id.

drsCloudRequest.context = context;
[drsCloudRequest sendWithBlock:^(id response, NSError *error)
{
if (response)
Copy link
Member

Choose a reason for hiding this comment

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

should we return error if there's no response?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed

return [@"adfs" isEqualToString:tenant];
}
return NO;
return [s_trustedHostList containsObject:host.lowercaseString];
Copy link
Member

Choose a reason for hiding this comment

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

if it's a base MSIDAuthority class, AAD authorities shouldn't be known


if (validate && ![authority isKnown])
{
__auto_type error = MSIDCreateError(MSIDErrorDomain, MSIDErrorServerInvalidRequest, @"Authority validation is not supported for this type of authority", nil, nil, nil, context.correlationId, nil);
Copy link
Member

Choose a reason for hiding this comment

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

B2C should also have openid configuration endpoint. Can we reuse the same logic here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I suggest to merge current pr first, and then we can add opend id endpoint support to B2C. Currently MSAL doesn't support it anyway.

@@ -191,7 +192,10 @@ - (void)webView:(WKWebView *)webView decidePolicyForNavigationAction:(WKNavigati
{
NSURL *requestURL = navigationAction.request.URL;

MSID_LOG_VERBOSE(self.context, @"-decidePolicyForNavigationAction host: %@", [MSIDAuthority isKnownHost:requestURL] ? requestURL.host : @"unknown host");
// __auto_type authorityFactory = [MSIDAuthorityFactory new];
// __auto_type authority = [authorityFactory authorityFromUrl:account.authority rawTenant:response.idTokenObj.realm context:nil error:nil];
Copy link
Member

Choose a reason for hiding this comment

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

nit: remove this

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

@antrix1989 antrix1989 changed the base branch from dev to sedemche/authorityAliases August 28, 2018 02:41
Copy link
Member

@oldalton oldalton left a comment

Choose a reason for hiding this comment

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

Added a couple of comments. I'll do a more thorough pass after this PR and #130 get the latest update from dev.

@@ -33,6 +35,14 @@ + (void)initialize
if (self == [MSIDAADNetworkConfiguration self])
{
s_defaultConfiguration = [MSIDAADNetworkConfiguration new];

s_trustedHostList = [NSSet setWithObjects:MSIDTrustedAuthority,
Copy link
Member

Choose a reason for hiding this comment

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

please see a comment in another PR about making sure the list of authorities is up to date

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

extern NSString * _Nonnull const MSID_OS_VER_KEY;//iOS/OSX version
extern NSString * _Nonnull const MSID_DEVICE_MODEL_KEY;//E.g. iPhone 5S

extern NSString * _Nonnull const MSIDTrustedAuthority;
Copy link
Member

Choose a reason for hiding this comment

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

nit: can we follow the same format as other constants?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Decided to keep camel case constants and change upper case constants to camel case latter.


if (authorityUrl)
{
requestUrl = [requestUrl msidURLForPreferredHost:[authorityUrl msidHostWithPortIfNecessary] context:nil error:nil];
Copy link
Member

Choose a reason for hiding this comment

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

So, what it does, it tries to replace the host of request url with host from network url. Can we just query for network host and swap the hosts? Or at least add a more thorough comment. This logic is a bit confusing to read.

- (NSURL *)cacheUrlWithContext:(id<MSIDRequestContext>)context
{
__auto_type universalAuthorityURL = [self universalAuthorityURL];
__auto_type authority = (MSIDAADAuthority *)[self.authorityFactory authorityFromUrl:universalAuthorityURL context:context error:nil];
Copy link
Member

Choose a reason for hiding this comment

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

nit: why are we ignoring error?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

authorityFactory internally will write to logs if parsing has failed.


- (nonnull NSString *)authorityType
{
return MSID_TELEMETRY_VALUE_AUTHORITY_AAD;
Copy link
Member

Choose a reason for hiding this comment

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

nit: it's a bit weird to use a telemetry constant for authority type here. Can we rename the constant or rename the method to telemetryAuthorityType?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

renamed to telemetryAuthorityType

+ (BOOL)isADFSInstanceURL:(nonnull NSURL *)endpointUrl;
+ (BOOL)isConsumerInstanceURL:(nonnull NSURL *)authorityURL;
+ (BOOL)isB2CInstanceURL:(nonnull NSURL *)endpointUrl;
- (nonnull NSArray<NSURL *> *)cacheAliases;
Copy link
Member

Choose a reason for hiding this comment

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

In the new cache we don't operate based on alias URLs, we operate based on environments which are strings. How can we now get a list of environment aliases?

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 still can get them from MSIDOauth2Factory. On the other hand, I don't think that MSIDOauth2Factory is a right place for such logic, that is why I suggest to revise it latter, see #222.


if (error)
{
*error = MSIDCreateError(MSIDErrorDomain, MSIDErrorInvalidDeveloperParameter, @"Provided authority url is not a valid authority.", nil, nil, nil, context.correlationId, nil);
Copy link
Member

Choose a reason for hiding this comment

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

Should we create a base OIDC authority instead?
Let's create an issue to follow up... (don't block on this)

Copy link
Contributor Author

@antrix1989 antrix1989 Sep 7, 2018

Choose a reason for hiding this comment

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

Probably we should. Created issue: #224

if (b2cAuthority) return b2cAuthority;
}

if ([MSIDAADAuthority isAuthorityFormatValid:url context:context error:nil])
Copy link
Member

Choose a reason for hiding this comment

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

this checks for MSIDAADAuthority and creates ADFS authority

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed

{
if ([MSIDB2CAuthority isAuthorityFormatValid:url context:context error:nil])
{
__auto_type b2cAuthority = [[MSIDB2CAuthority alloc] initWithURL:url rawTenant:rawTenant context:context error:nil];
Copy link
Member

Choose a reason for hiding this comment

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

none of the initializers takes error?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added underlyingError.

context:(id<MSIDRequestContext>)context
error:(NSError **)error
{
if ([MSIDB2CAuthority isAuthorityFormatValid:url context:context error:nil])
Copy link
Member

Choose a reason for hiding this comment

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

this code looks quite similar to the next one except there's no tenant. Can we just pass nil tenant to initializer?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

good point, refactored.

@antrix1989 antrix1989 changed the base branch from sedemche/authorityAliases to dev August 29, 2018 00:27
@antrix1989 antrix1989 changed the base branch from dev to sedemche/authorityAliases August 29, 2018 00:27
@antrix1989 antrix1989 changed the base branch from sedemche/authorityAliases to dev September 4, 2018 19:00
Copy link
Member

@oldalton oldalton left a comment

Choose a reason for hiding this comment

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

Added a couple of more suggestions, but otherwise the changes look fine to me after comments are addressed. I'm also seeing a couple of issues that have been fixes in other PR, so we need to merge dev back into this PR.

{
s_defaultConfiguration = [MSIDAADNetworkConfiguration new];

s_trustedHostList = [NSSet setWithObjects:MSIDTrustedAuthority,
Copy link
Member

Choose a reason for hiding this comment

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

I think you added more hosts into here in another PR?


- (NSSet<NSString *> *)trustedHosts
{
return s_trustedHostList;
Copy link
Member

Choose a reason for hiding this comment

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

nit: remove ;

- (void)setObject:(id)obj forKey:(id)key
{
dispatch_barrier_sync(self.synchronizationQueue, ^{
[self.container setObject:obj forKey:key];
Copy link
Member

Choose a reason for hiding this comment

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

I think you fixed this to use subscript in another PR?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes, it was fixed in another PR.

@@ -26,8 +26,6 @@ extern NSString *const MSID_OAUTH2_AUTHORIZATION;
extern NSString *const MSID_OAUTH2_AUTHORIZATION_CODE;
extern NSString *const MSID_OAUTH2_AUTHORIZATION_URI;
extern NSString *const MSID_OAUTH2_AUTHORITY;
extern NSString *const MSID_OAUTH2_AUTHORIZE_SUFFIX;
Copy link
Member

@oldalton oldalton Sep 5, 2018

Choose a reason for hiding this comment

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

those constants are still used in ADAL. Please revert removal...

@@ -229,8 +231,8 @@ - (MSIDAccessToken *)getAccessTokenForAccount:(MSIDAccountIdentifier *)account

MSIDDefaultCredentialCacheQuery *query = [MSIDDefaultCredentialCacheQuery new];
query.homeAccountId = account.homeAccountId;
query.environment = configuration.authority.msidHostWithPortIfNecessary;
query.realm = configuration.authority.msidTenant;
query.environment = configuration.authority.url.msidHostWithPortIfNecessary;
Copy link
Member

Choose a reason for hiding this comment

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

maybe we can have "host" method in authority object itself? That way we can avoid recalculating it every time through msidHostWithPortIfNecessary.

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

query.environment = accessToken.authority.msidHostWithPortIfNecessary;
query.realm = accessToken.authority.msidTenant;
query.environment = accessToken.authority.url.msidHostWithPortIfNecessary;
query.realm = accessToken.authority.url.msidTenant;
Copy link
Member

Choose a reason for hiding this comment

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

don't we have tenant in authority object itself?

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 have tenant in MSIDAADAuthority, but since authority here is MSIDAuthority, we can not get tenant without dynamic cast to MSIDAADAuthority.

- (id)copyWithZone:(NSZone *)zone
{
MSIDAADAuthority *authority = [super copyWithZone:zone];
authority->_tenant = [_tenant copyWithZone:zone];
Copy link
Member

Choose a reason for hiding this comment

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

did it get done?

@antrix1989 antrix1989 merged commit 624cd6b into dev Sep 12, 2018
@antrix1989 antrix1989 deleted the sedemche/split_authorities branch September 12, 2018 00:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants