Skip to content

Commit 9acc5b8

Browse files
committed
2 parents 089ec9f + bf0c8dc commit 9acc5b8

File tree

4 files changed

+61
-1
lines changed

4 files changed

+61
-1
lines changed

IdentityCore/src/oauth2/aad_base/MSIDAADTokenResponse.m

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ @implementation MSIDAADTokenResponse
4343
MSID_JSON_ACCESSOR(MSID_OAUTH2_RESOURCE, resource)
4444
MSID_JSON_RW(MSID_OAUTH2_CLIENT_INFO, rawClientInfo, setRawClientInfo)
4545
MSID_JSON_ACCESSOR(MSID_FAMILY_ID, familyId)
46+
MSID_JSON_RW(MSID_OAUTH2_REFRESH_TOKEN, refreshToken, setRefreshToken)
4647
MSID_JSON_ACCESSOR(MSID_TELEMETRY_KEY_SPE_INFO, speInfo)
4748

4849
- (instancetype)initWithJSONDictionary:(NSDictionary *)json
@@ -58,6 +59,11 @@ - (instancetype)initWithJSONDictionary:(NSDictionary *)json
5859
self.rawClientInfo = token.clientInfo.rawClientInfo;
5960
_clientInfo = token.clientInfo;
6061
}
62+
63+
if (token && [NSString msidIsStringNilOrBlank:self.refreshToken])
64+
{
65+
self.refreshToken = token.refreshToken;
66+
}
6167

6268
[self initDerivedProperties];
6369
}

IdentityCore/tests/MSIDAADTokenResponseTests.m

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ - (void)testExtendedExpiryDate_whenExtendedExpiresInNotAvailable_shouldReturnNil
173173

174174
#pragma mark - Refresh token
175175

176-
- (void)testInitWithJson_andRefreshToken_shouldTakeFieldsFromRefreshToken
176+
- (void)testInitWithJson_andRefreshToken_andNilClientInfoInResponse_shouldTakeClientInfoFromRefreshToken
177177
{
178178
NSDictionary *jsonInput = @{@"access_token": @"at",
179179
@"token_type": @"Bearer",
@@ -198,6 +198,26 @@ - (void)testInitWithJson_andRefreshToken_shouldTakeFieldsFromRefreshToken
198198
XCTAssertEqualObjects(response.clientInfo, clientInfo);
199199
}
200200

201+
- (void)testInitWithJson_andRefreshToken_andNilRefreshTokenInResponse_shouldTakeRefreshTokenFromInput
202+
{
203+
NSDictionary *jsonInput = @{@"access_token": @"at",
204+
@"token_type": @"Bearer",
205+
@"expires_in": @"3600"};
206+
207+
MSIDRefreshToken *refreshToken = [MSIDRefreshToken new];
208+
refreshToken.refreshToken = @"rt from refresh token";
209+
210+
NSError *error = nil;
211+
MSIDAADTokenResponse *response = [[MSIDAADTokenResponse alloc] initWithJSONDictionary:jsonInput
212+
refreshToken:refreshToken
213+
error:&error];
214+
215+
XCTAssertNotNil(response);
216+
XCTAssertNil(error);
217+
218+
XCTAssertEqualObjects(response.refreshToken, @"rt from refresh token");
219+
}
220+
201221
- (void)testInitWithJson_andNilRefreshToken_shouldNotTakeFieldsFromRefreshToken
202222
{
203223
NSDictionary *jsonInput = @{@"access_token": @"at",
@@ -227,6 +247,7 @@ - (void)testInitWithJson_andRefreshToken_shouldNotTakeFieldsFromRefreshTokenAndU
227247
};
228248

229249
MSIDRefreshToken *refreshToken = [MSIDRefreshToken new];
250+
refreshToken.refreshToken = @"rt2";
230251

231252
MSIDClientInfo *clientInfo = [MSIDClientInfo new];
232253
[clientInfo setValue:@"clientinfo" forKey:@"rawClientInfo"];
@@ -242,6 +263,7 @@ - (void)testInitWithJson_andRefreshToken_shouldNotTakeFieldsFromRefreshTokenAndU
242263
XCTAssertNil(error);
243264

244265
XCTAssertEqualObjects(response.clientInfo.rawClientInfo, clientInfoString);
266+
XCTAssertEqualObjects(response.refreshToken, @"rt");
245267
}
246268

247269
@end

IdentityCore/tests/automation/MSIDTestAccountsProvider.h

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,30 @@
2929

3030
- (instancetype)init NS_UNAVAILABLE;
3131

32+
/*
33+
This information would normally come from a configuration file.
34+
@param certificate Base64 encoded client certificate to authenticate with keyvault
35+
@param password Certificate password in case it's password protected
36+
@param additionalConfigurations Additional local configurations that should override server configurations
37+
@param appInstallLinks Information necessary to install additional apps to run multi-app tests, e.g.
38+
39+
"msal": {
40+
"install_url": "https://...",
41+
"app_bundle_id": "com.microsoft.MSALTestApp",
42+
"app_name": "MSAL Test App"
43+
},
44+
"broker": {
45+
"install_url": "https://...",
46+
"app_bundle_id": "com.microsoft.broker",
47+
"app_name": "Broker"
48+
}
49+
@param apiPath Lab API path
50+
*/
51+
3252
- (instancetype)initWithClientCertificateContents:(NSString *)certificate
3353
certificatePassword:(NSString *)password
3454
additionalConfigurations:(NSDictionary *)additionalConfigurations
55+
appInstallLinks:(NSDictionary *)appInstallLinks
3556
apiPath:(NSString *)apiPath;
3657

3758
- (instancetype)initWithConfigurationPath:(NSString *)configurationPath;
@@ -42,4 +63,6 @@
4263
- (void)passwordForAccount:(MSIDTestAccount *)account
4364
completionHandler:(void (^)(NSString *password))completionHandler;
4465

66+
- (NSDictionary *)appInstallForConfiguration:(NSString *)appId;
67+
4568
@end

IdentityCore/tests/automation/MSIDTestAccountsProvider.m

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
@interface MSIDTestAccountsProvider()
2828

2929
@property (nonatomic, strong) NSMutableDictionary *cachedConfigurations;
30+
@property (nonatomic, strong) NSDictionary *appInstallLinks;
3031
@property (nonatomic, strong) KeyvaultAuthentication *keyvaultAuthentication;
3132
@property (nonatomic, strong) NSString *apiPath;
3233

@@ -37,6 +38,7 @@ @implementation MSIDTestAccountsProvider
3738
- (instancetype)initWithClientCertificateContents:(NSString *)certificate
3839
certificatePassword:(NSString *)password
3940
additionalConfigurations:(NSDictionary *)additionalConfigurations
41+
appInstallLinks:(NSDictionary *)appInstallLinks
4042
apiPath:(NSString *)apiPath
4143
{
4244
self = [super init];
@@ -47,6 +49,7 @@ - (instancetype)initWithClientCertificateContents:(NSString *)certificate
4749
_keyvaultAuthentication = [[KeyvaultAuthentication alloc] initWithCertContents:certificate certPassword:password];
4850
_apiPath = apiPath;
4951
[_cachedConfigurations addEntriesFromDictionary:additionalConfigurations];
52+
_appInstallLinks = appInstallLinks;
5053
}
5154

5255
return self;
@@ -90,10 +93,16 @@ - (instancetype)initWithConfigurationPath:(NSString *)configurationPath
9093
return [self initWithClientCertificateContents:encodedCertificate
9194
certificatePassword:certificatePassword
9295
additionalConfigurations:additionalConfsDictionary
96+
appInstallLinks:configurationDictionary[@"app_install_urls"]
9397
apiPath:apiPath];
9498

9599
}
96100

101+
- (NSDictionary *)appInstallForConfiguration:(NSString *)appId
102+
{
103+
return _appInstallLinks[appId];
104+
}
105+
97106
- (void)configurationWithRequest:(MSIDTestAutomationConfigurationRequest *)request
98107
completionHandler:(void (^)(MSIDTestAutomationConfiguration *configuration))completionHandler
99108
{

0 commit comments

Comments
 (0)