Skip to content

Commit 91b45d1

Browse files
committed
Read BART from ests response when refresh_token_type & set deviceID
1 parent 6b973be commit 91b45d1

File tree

8 files changed

+26
-0
lines changed

8 files changed

+26
-0
lines changed

IdentityCore/src/MSIDBrokerConstants.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ extern NSString * _Nonnull const MSID_IS_CALLER_MANAGED_KEY;
9999
extern NSString * _Nonnull const MSID_BROKER_PREFERRED_AUTH_CONFIGURATION_KEY;
100100
extern NSString * _Nonnull const MSID_BROKER_CLIENT_FLIGHTS_KEY;
101101
extern NSString * _Nonnull const MSID_BROKER_SDM_WPJ_ATTEMPTED;
102+
extern NSString * _Nonnull const MSID_BART_DEVICE_ID_KEY;
102103
extern NSString * _Nonnull const MSID_EXP_RETRY_ON_NETWORK;
103104
extern NSString * _Nonnull const MSID_EXP_ENABLE_CONNECTION_CLOSE;
104105
extern NSString * _Nonnull const MSID_HTTP_CONNECTION;

IdentityCore/src/MSIDBrokerConstants.m

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@
9797
NSString *const MSID_JIT_TROUBLESHOOTING_HOST = @"jit_troubleshooting";
9898
NSString *const MSID_IS_CALLER_MANAGED_KEY = @"isCallerAppManaged";
9999
NSString *const MSID_BROKER_SDM_WPJ_ATTEMPTED = @"sdm_reg_attempted";
100+
NSString *const MSID_BART_DEVICE_ID_KEY = @"bart_device_id";
100101
NSString *const MSID_FORCE_REFRESH_KEY = @"force_refresh";
101102

102103
// Experiments

IdentityCore/src/MSIDOAuth2Constants.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,4 +179,6 @@ extern NSString *const MSID_CCS_REQUEST_ID_RESPONSE;
179179

180180
extern NSString *const MSID_CCS_REQUEST_SEQUENCE_KEY;
181181
extern NSString *const MSID_CCS_REQUEST_SEQUENCE_RESPONSE;
182+
extern NSString *const MSID_REFRESH_TOKEN_TYPE;
183+
extern NSString *const MSID_REFRESH_TOKEN_TYPE_BOUND_APP_RT;
182184
extern NSString *const MSID_BOUND_DEVICE_ID_CACHE_KEY;

IdentityCore/src/MSIDOAuth2Constants.m

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,4 +180,6 @@
180180
NSString *const MSID_CCS_REQUEST_SEQUENCE_KEY = @"x-ms-srs";
181181
NSString *const MSID_CCS_REQUEST_SEQUENCE_RESPONSE = @"ccs-request-sequence";
182182

183+
NSString *const MSID_REFRESH_TOKEN_TYPE = @"refresh_token_type";
184+
NSString *const MSID_REFRESH_TOKEN_TYPE_BOUND_APP_RT = @"bound_app_rt";
183185
NSString *const MSID_BOUND_DEVICE_ID_CACHE_KEY = @"bound_device_id";

IdentityCore/src/oauth2/MSIDOauth2Factory.m

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#import "MSIDAccessToken.h"
2828
#import "MSIDBaseToken.h"
2929
#import "MSIDRefreshToken.h"
30+
#import "MSIDBoundRefreshToken.h"
3031
#import "MSIDLegacySingleResourceToken.h"
3132
#import "MSIDIdToken.h"
3233
#import "MSIDAccount.h"
@@ -170,6 +171,15 @@ - (MSIDRefreshToken *)refreshTokenFromResponse:(MSIDTokenResponse *)response
170171
BOOL result = [self fillRefreshToken:refreshToken fromResponse:response configuration:configuration];
171172

172173
if (!result) return nil;
174+
if (refreshToken)
175+
{
176+
// Saving RT from a token network response
177+
if ([response.additionalServerInfo[MSID_REFRESH_TOKEN_TYPE] isEqualToString:MSID_REFRESH_TOKEN_TYPE_BOUND_APP_RT])
178+
{
179+
MSIDBoundRefreshToken *bart = [[MSIDBoundRefreshToken alloc] initWithRefreshToken:refreshToken boundDeviceId:response.boundAppRefreshTokenDeviceId];
180+
return bart;
181+
}
182+
}
173183
return refreshToken;
174184
}
175185

IdentityCore/src/oauth2/MSIDTokenResponse.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,8 @@
9595

9696
@property (nonatomic) BOOL createdFromCache;
9797

98+
@property (nonatomic, nullable) NSString *boundAppRefreshTokenDeviceId;
99+
98100
- (nullable instancetype)initWithJSONDictionary:(nonnull NSDictionary *)json
99101
refreshToken:(nullable MSIDBaseToken<MSIDRefreshableToken> *)token
100102
error:(NSError * _Nullable __autoreleasing *_Nullable)error;

IdentityCore/src/oauth2/MSIDTokenResponse.m

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,7 @@ - (instancetype)initWithJSONDictionary:(NSDictionary *)json error:(NSError *__au
170170
_stsErrorCodes = [json msidArrayOfIntegersForKey: MSID_OAUTH2_ERROR_CODES];
171171
_errorDescription = [[json msidStringObjectForKey:MSID_OAUTH2_ERROR_DESCRIPTION] msidURLDecode];
172172
_clientAppVersion = [json msidStringObjectForKey:MSID_BROKER_CLIENT_APP_VERSION_KEY];
173+
_boundAppRefreshTokenDeviceId = [json msidStringObjectForKey:MSID_BART_DEVICE_ID_KEY];
173174
[self setAdditionalServerInfo:json];
174175
}
175176

IdentityCore/src/requests/sdk/MSIDTokenResponseValidator.m

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
#import "MSIDBrokerResponse.h"
3030
#import "MSIDAccessToken.h"
3131
#import "MSIDRefreshToken.h"
32+
#import "MSIDBoundRefreshToken.h"
3233
#import "MSIDBasicContext.h"
3334
#import "MSIDAccountMetadataCacheAccessor.h"
3435
#import "MSIDAccountIdentifier.h"
@@ -261,6 +262,12 @@ - (MSIDTokenResult *)validateAndSaveTokenResponse:(MSIDTokenResponse *)tokenResp
261262
return nil;
262263
}
263264

265+
if ([tokenResponse.additionalServerInfo[MSID_REFRESH_TOKEN_TYPE] isEqualToString:MSID_REFRESH_TOKEN_TYPE_BOUND_APP_RT] && tokenResponse.boundAppRefreshTokenDeviceId)
266+
{
267+
tokenResult.refreshToken = [[MSIDBoundRefreshToken alloc] initWithRefreshToken:(MSIDRefreshToken *)tokenResult.refreshToken
268+
boundDeviceId:tokenResponse.boundAppRefreshTokenDeviceId];
269+
}
270+
264271
//save metadata
265272
NSError *authorityError;
266273
MSIDAuthority *resultingAuthority = [factory resultAuthorityWithConfiguration:parameters.msidConfiguration tokenResponse:tokenResponse error:&authorityError];

0 commit comments

Comments
 (0)