Skip to content

Commit 666dde7

Browse files
authored
Merge pull request #1548 from AzureAD/ameyapat/bound-refresh-token-object
Adding Bound refresh token class and cache item
2 parents 8d78d3c + d716f63 commit 666dde7

15 files changed

+909
-5
lines changed

IdentityCore/IdentityCore.xcodeproj/project.pbxproj

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -758,6 +758,14 @@
758758
7293580E2DDFADDF0001D03C /* MSIDNonceHttpRequest.h in Headers */ = {isa = PBXBuildFile; fileRef = 7293580D2DDFADC80001D03C /* MSIDNonceHttpRequest.h */; };
759759
729358102DDFADE70001D03C /* MSIDNonceHttpRequest.m in Sources */ = {isa = PBXBuildFile; fileRef = 7293580F2DDFADE50001D03C /* MSIDNonceHttpRequest.m */; };
760760
729358112DDFADE70001D03C /* MSIDNonceHttpRequest.m in Sources */ = {isa = PBXBuildFile; fileRef = 7293580F2DDFADE50001D03C /* MSIDNonceHttpRequest.m */; };
761+
72C1EBF52DE91AC8004C40A4 /* MSIDBoundRefreshToken.h in Headers */ = {isa = PBXBuildFile; fileRef = 72C1EBF42DE91ABE004C40A4 /* MSIDBoundRefreshToken.h */; };
762+
72C1EBF72DE91AD0004C40A4 /* MSIDBoundRefreshToken.m in Sources */ = {isa = PBXBuildFile; fileRef = 72C1EBF62DE91ACC004C40A4 /* MSIDBoundRefreshToken.m */; };
763+
72C1EBF82DE91AD0004C40A4 /* MSIDBoundRefreshToken.m in Sources */ = {isa = PBXBuildFile; fileRef = 72C1EBF62DE91ACC004C40A4 /* MSIDBoundRefreshToken.m */; };
764+
72C1EBFC2DEA8199004C40A4 /* MSIDBoundRefreshTokenCacheItem.h in Headers */ = {isa = PBXBuildFile; fileRef = 72C1EBFB2DEA8185004C40A4 /* MSIDBoundRefreshTokenCacheItem.h */; };
765+
72C1EBFE2DEA81A1004C40A4 /* MSIDBoundRefreshTokenCacheItem.m in Sources */ = {isa = PBXBuildFile; fileRef = 72C1EBFD2DEA819E004C40A4 /* MSIDBoundRefreshTokenCacheItem.m */; };
766+
72C1EBFF2DEA81A1004C40A4 /* MSIDBoundRefreshTokenCacheItem.m in Sources */ = {isa = PBXBuildFile; fileRef = 72C1EBFD2DEA819E004C40A4 /* MSIDBoundRefreshTokenCacheItem.m */; };
767+
72C764F92E09CFB800043AB1 /* MSIDBoundRefreshTokenTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 72C764F82E09CFA400043AB1 /* MSIDBoundRefreshTokenTests.m */; };
768+
72C764FA2E09CFB800043AB1 /* MSIDBoundRefreshTokenTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 72C764F82E09CFA400043AB1 /* MSIDBoundRefreshTokenTests.m */; };
761769
72D961AE2DE12F1F005DED66 /* MSIDCachedNonce.h in Headers */ = {isa = PBXBuildFile; fileRef = 72D961AD2DE12F19005DED66 /* MSIDCachedNonce.h */; };
762770
72D961B02DE12F30005DED66 /* MSIDCachedNonce.m in Sources */ = {isa = PBXBuildFile; fileRef = 72D961AF2DE12F2E005DED66 /* MSIDCachedNonce.m */; };
763771
72D961B12DE12F30005DED66 /* MSIDCachedNonce.m in Sources */ = {isa = PBXBuildFile; fileRef = 72D961AF2DE12F2E005DED66 /* MSIDCachedNonce.m */; };
@@ -2668,6 +2676,11 @@
26682676
729357F22DDBD3F60001D03C /* MSIDNonceTokenRequestTest.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = MSIDNonceTokenRequestTest.m; sourceTree = "<group>"; };
26692677
7293580D2DDFADC80001D03C /* MSIDNonceHttpRequest.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MSIDNonceHttpRequest.h; sourceTree = "<group>"; };
26702678
7293580F2DDFADE50001D03C /* MSIDNonceHttpRequest.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = MSIDNonceHttpRequest.m; sourceTree = "<group>"; };
2679+
72C1EBF42DE91ABE004C40A4 /* MSIDBoundRefreshToken.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MSIDBoundRefreshToken.h; sourceTree = "<group>"; };
2680+
72C1EBF62DE91ACC004C40A4 /* MSIDBoundRefreshToken.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = MSIDBoundRefreshToken.m; sourceTree = "<group>"; };
2681+
72C1EBFB2DEA8185004C40A4 /* MSIDBoundRefreshTokenCacheItem.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MSIDBoundRefreshTokenCacheItem.h; sourceTree = "<group>"; };
2682+
72C1EBFD2DEA819E004C40A4 /* MSIDBoundRefreshTokenCacheItem.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = MSIDBoundRefreshTokenCacheItem.m; sourceTree = "<group>"; };
2683+
72C764F82E09CFA400043AB1 /* MSIDBoundRefreshTokenTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = MSIDBoundRefreshTokenTests.m; sourceTree = "<group>"; };
26712684
72D961AD2DE12F19005DED66 /* MSIDCachedNonce.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MSIDCachedNonce.h; sourceTree = "<group>"; };
26722685
72D961AF2DE12F2E005DED66 /* MSIDCachedNonce.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = MSIDCachedNonce.m; sourceTree = "<group>"; };
26732686
740340B72460E5C400DFCF27 /* MSIDCurrentRequestTelemetrySerializedItem.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MSIDCurrentRequestTelemetrySerializedItem.h; sourceTree = "<group>"; };
@@ -4809,6 +4822,8 @@
48094822
B226D85B1FFB07840012BF8B /* token */ = {
48104823
isa = PBXGroup;
48114824
children = (
4825+
72C1EBFD2DEA819E004C40A4 /* MSIDBoundRefreshTokenCacheItem.m */,
4826+
72C1EBFB2DEA8185004C40A4 /* MSIDBoundRefreshTokenCacheItem.h */,
48124827
B4A5ACD021F7F1DF00D2A780 /* Matchers */,
48134828
0570FE7D219B8C8C00958ECF /* MSIDCredentialCacheItem+MSIDBaseToken.h */,
48144829
0570FE7C219B8C8C00958ECF /* MSIDCredentialCacheItem+MSIDBaseToken.m */,
@@ -4911,6 +4926,8 @@
49114926
B251CC232041050E005E0179 /* token */ = {
49124927
isa = PBXGroup;
49134928
children = (
4929+
72C1EBF62DE91ACC004C40A4 /* MSIDBoundRefreshToken.m */,
4930+
72C1EBF42DE91ABE004C40A4 /* MSIDBoundRefreshToken.h */,
49144931
B2675689228CE6FC000F01D7 /* protocols */,
49154932
B251CC4E204105AD005E0179 /* MSIDCredentialType.h */,
49164933
B251CC4F204105AD005E0179 /* MSIDCredentialType.m */,
@@ -5717,6 +5734,7 @@
57175734
D6DA89731FBA6A4E004C56C7 /* tests */ = {
57185735
isa = PBXGroup;
57195736
children = (
5737+
72C764F82E09CFA400043AB1 /* MSIDBoundRefreshTokenTests.m */,
57205738
720B5B572DD58A6A00318FE5 /* MSIDJWECryptoTests.m */,
57215739
729357F22DDBD3F60001D03C /* MSIDNonceTokenRequestTest.m */,
57225740
A0410E4F25E88B5E004D80FD /* MSIDThrottlingMetaDataTest.m */,
@@ -6364,6 +6382,7 @@
63646382
B2F671EC2467AB4500649855 /* MSIDInteractiveRequestControlling.h in Headers */,
63656383
B443F0002AD6327700782168 /* MSIDBrokerOperationPasskeyCredentialRequest.h in Headers */,
63666384
23AE20982342D3BF00108F76 /* MSIDSilentController+Internal.h in Headers */,
6385+
72C1EBF52DE91AC8004C40A4 /* MSIDBoundRefreshToken.h in Headers */,
63676386
23B39A8620993572000AA905 /* MSIDAADAuthorityMetadataRequest.h in Headers */,
63686387
B28D90AA218FD1F800E230D6 /* MSIDDefaultTokenResponseValidator.h in Headers */,
63696388
B2F671E82467A34400649855 /* MSIDAuthorizationCodeResult.h in Headers */,
@@ -6408,6 +6427,7 @@
64086427
B286B9CB2389DE9F007833AD /* MSIDKeyGenerator.h in Headers */,
64096428
B26CEB022367B3B9009E6E54 /* MSIDSystemWebViewControllerFactory.h in Headers */,
64106429
8878C62929DCA054002F5F4B /* MSIDCIAMOauth2Factory.h in Headers */,
6430+
72C1EBFC2DEA8199004C40A4 /* MSIDBoundRefreshTokenCacheItem.h in Headers */,
64116431
B2C7088D2198E48E00D917B8 /* NSData+MSIDAES.h in Headers */,
64126432
2394F2052D4894FF00E44F6E /* MSIDWebUpgradeRegOperation.h in Headers */,
64136433
B251CC3B2041058D005E0179 /* MSIDRefreshToken.h in Headers */,
@@ -7077,6 +7097,7 @@
70777097
9668B6F72148796A0039AB0A /* MSIDDataExtensionsTests.m in Sources */,
70787098
B286B9F12389F866007833AD /* MSIDWebviewFactoryTests.m in Sources */,
70797099
B252913B2096698100E78695 /* MSIDAADIdTokenClaimsFactoryTests.m in Sources */,
7100+
72C764FA2E09CFB800043AB1 /* MSIDBoundRefreshTokenTests.m in Sources */,
70807101
B2BE923121A0EFB100F5AB8C /* MSIDDefaultTokenRequestProviderTests.m in Sources */,
70817102
729357F42DDBD3F80001D03C /* MSIDNonceTokenRequestTest.m in Sources */,
70827103
23FB5C20225516FB002BF1EB /* MSIDClaimsRequestTests.m in Sources */,
@@ -7274,6 +7295,7 @@
72747295
583BFCA924D87BA40035B901 /* MSIDRedirectUri.m in Sources */,
72757296
E656E07B2C2627B80011FB23 /* MSIDWebUpgradeRegResponse.m in Sources */,
72767297
580E2547271A014F003D1795 /* MSIDDeviceHeader.m in Sources */,
7298+
72C1EBFF2DEA81A1004C40A4 /* MSIDBoundRefreshTokenCacheItem.m in Sources */,
72777299
583BFCAB24D88CED0035B901 /* MSIDRedirectUriVerifier.m in Sources */,
72787300
B253152723DD61FB00432133 /* MSIDSSOExtensionGetDeviceInfoRequest.m in Sources */,
72797301
2A24815F2CB08344006FCB34 /* MSIDXpcSilentTokenRequestController.m in Sources */,
@@ -7304,6 +7326,7 @@
73047326
1E7DC42A2405A95400740BAD /* MSIDBaseBrokerOperationRequest.m in Sources */,
73057327
B286B97F2389DC08007833AD /* MSIDBrokerOperationRequest.m in Sources */,
73067328
23FB5C3122551866002BF1EB /* MSIDClaimsRequest+ClientCapabilities.m in Sources */,
7329+
72C1EBF72DE91AD0004C40A4 /* MSIDBoundRefreshToken.m in Sources */,
73077330
23B39ACD209CF317000AA905 /* MSIDAADNetworkConfiguration.m in Sources */,
73087331
23FB5C462255A135002BF1EB /* MSIDIndividualClaimRequest.m in Sources */,
73097332
2A2481582CB08050006FCB34 /* MSIDXpcSingleSignOnProvider.m in Sources */,
@@ -7755,6 +7778,7 @@
77557778
B2BE926221A25A8600F5AB8C /* MSIDInteractiveControllerIntegrationTests.m in Sources */,
77567779
B2BE923521A0F80100F5AB8C /* MSIDLegacyTokenRequestProviderTests.m in Sources */,
77577780
B48FC0632D7A90FA007B80DB /* MSIDBrokerFlightProviderTests.m in Sources */,
7781+
72C764F92E09CFB800043AB1 /* MSIDBoundRefreshTokenTests.m in Sources */,
77587782
23FB5C21225516FB002BF1EB /* MSIDClaimsRequestTests.m in Sources */,
77597783
E75DD02625D5E474007664A6 /* MSIDThrottlingServiceIntegrationTests.m in Sources */,
77607784
B286BA07238A110A007833AD /* MSIDOIDCSignoutRequestTests.m in Sources */,
@@ -7984,6 +8008,7 @@
79848008
2394F1F92D4890BD00E44F6E /* MSIDWebOAuth2AuthCodeOperation.m in Sources */,
79858009
238EF03E208FE4740035ABE6 /* MSIDRefreshTokenGrantRequest.m in Sources */,
79868010
230C2C472CF95DBC00E767B6 /* MSIDSwitchBrowserResumeResponse.m in Sources */,
8011+
72C1EBFE2DEA81A1004C40A4 /* MSIDBoundRefreshTokenCacheItem.m in Sources */,
79878012
A0C7DDA425D1EA0D00F5B5B6 /* NSError+MSIDThrottlingExtension.m in Sources */,
79888013
235480C720DDF81000246F72 /* MSIDAuthorityFactory.m in Sources */,
79898014
239DF9C920E05847002D428B /* MSIDAADRequestConfigurator.m in Sources */,
@@ -8210,6 +8235,7 @@
82108235
B286B96323861852007833AD /* MSIDSignoutWebRequestConfiguration.m in Sources */,
82118236
B49323982AD4DA4800E0CBC0 /* MSIDBrokerOperationGetPasskeyAssertionResponse.m in Sources */,
82128237
B2C708182195283500D917B8 /* MSIDBrokerTokenRequest.m in Sources */,
8238+
72C1EBF82DE91AD0004C40A4 /* MSIDBoundRefreshToken.m in Sources */,
82138239
232173E22182A998009852C6 /* NSDictionary+MSIDJsonSerializable.m in Sources */,
82148240
B2C707F42192524700D917B8 /* MSIDDefaultTokenRequestProvider.m in Sources */,
82158241
B20657BE1FC9254800412B7D /* MSIDTelemetryCacheEvent.m in Sources */,

IdentityCore/src/MSIDOAuth2Constants.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,7 @@ extern NSString *const MSID_ID_TOKEN_CACHE_TYPE;
157157
extern NSString *const MSID_LEGACY_ID_TOKEN_CACHE_TYPE;
158158
extern NSString *const MSID_PRT_TOKEN_CACHE_TYPE;
159159
extern NSString *const MSID_FRT_TOKEN_CACHE_TYPE;
160+
extern NSString *const MSID_BOUND_RT_TOKEN_CACHE_TYPE;
160161
extern NSString *const MSID_GENERAL_TOKEN_CACHE_TYPE;
161162
extern NSString *const MSID_GENERAL_CACHE_ITEM_TYPE;
162163
extern NSString *const MSID_APP_METADATA_CACHE_TYPE;
@@ -177,3 +178,4 @@ extern NSString *const MSID_CCS_REQUEST_ID_RESPONSE;
177178

178179
extern NSString *const MSID_CCS_REQUEST_SEQUENCE_KEY;
179180
extern NSString *const MSID_CCS_REQUEST_SEQUENCE_RESPONSE;
181+
extern NSString *const MSID_BOUND_DEVICE_ID_CACHE_KEY;

IdentityCore/src/MSIDOAuth2Constants.m

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,7 @@
151151
NSString *const MSID_LEGACY_ID_TOKEN_CACHE_TYPE = @"V1IdToken";
152152
NSString *const MSID_PRT_TOKEN_CACHE_TYPE = @"PrimaryRefreshToken";
153153
NSString *const MSID_FRT_TOKEN_CACHE_TYPE = @"FamilyRefreshToken";
154+
NSString *const MSID_BOUND_RT_TOKEN_CACHE_TYPE = @"BoundRefreshToken";
154155
NSString *const MSID_GENERAL_TOKEN_CACHE_TYPE = @"token";
155156
NSString *const MSID_GENERAL_CACHE_ITEM_TYPE = @"general_cache_item";
156157
NSString *const MSID_APP_METADATA_CACHE_TYPE = @"appmetadata";
@@ -177,3 +178,5 @@
177178

178179
NSString *const MSID_CCS_REQUEST_SEQUENCE_KEY = @"x-ms-srs";
179180
NSString *const MSID_CCS_REQUEST_SEQUENCE_RESPONSE = @"ccs-request-sequence";
181+
182+
NSString *const MSID_BOUND_DEVICE_ID_CACHE_KEY = @"bound_device_id";

IdentityCore/src/cache/accessor/MSIDAccountCredentialCache.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -388,7 +388,7 @@ - (BOOL)removeCredential:(nonnull MSIDCredentialCacheItem *)credential
388388

389389
BOOL result = [_dataSource removeTokensWithKey:key context:context error:error];
390390

391-
if (result && (credential.credentialType == MSIDRefreshTokenType || credential.credentialType == MSIDFamilyRefreshTokenType))
391+
if (result && (credential.credentialType == MSIDRefreshTokenType || credential.credentialType == MSIDFamilyRefreshTokenType || credential.credentialType == MSIDBoundRefreshTokenType))
392392
{
393393
[_dataSource saveWipeInfoWithContext:context error:nil];
394394
}

IdentityCore/src/cache/accessor/MSIDDefaultTokenCacheAccessor.m

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -299,18 +299,18 @@ - (MSIDRefreshToken *)getRefreshableTokenWithAccount:(MSIDAccountIdentifier *)ac
299299
NSString *credentialTypeString = nil;
300300
if (credentialType == MSIDPrimaryRefreshTokenType)
301301
{
302-
credentialTypeString = @"primary ";
302+
credentialTypeString = @"primary";
303303
}
304304
else if (credentialType == MSIDFamilyRefreshTokenType)
305305
{
306-
credentialTypeString = @"single family ";
306+
credentialTypeString = @"single family";
307307
}
308308
else
309309
{
310-
credentialTypeString = @"";
310+
credentialTypeString = [MSIDCredentialTypeHelpers credentialTypeAsString:credentialType];
311311
}
312312

313-
MSID_LOG_WITH_CTX(MSIDLogLevelVerbose, context, @"(Default accessor) Found %@refresh token by legacy account id", credentialTypeString);
313+
MSID_LOG_WITH_CTX(MSIDLogLevelVerbose, context, @"(Default accessor) Found %@ refresh token by legacy account id", credentialTypeString);
314314
return refreshToken;
315315
}
316316
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
//
2+
// Copyright (c) Microsoft Corporation.
3+
// All rights reserved.
4+
//
5+
// This code is licensed under the MIT License.
6+
//
7+
// Permission is hereby granted, free of charge, to any person obtaining a copy
8+
// of this software and associated documentation files(the "Software"), to deal
9+
// in the Software without restriction, including without limitation the rights
10+
// to use, copy, modify, merge, publish, distribute, sublicense, and / or sell
11+
// copies of the Software, and to permit persons to whom the Software is
12+
// furnished to do so, subject to the following conditions :
13+
//
14+
// The above copyright notice and this permission notice shall be included in
15+
// all copies or substantial portions of the Software.
16+
//
17+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23+
// THE SOFTWARE.
24+
25+
#import <Foundation/Foundation.h>
26+
#import "MSIDCredentialCacheItem.h"
27+
28+
/**
29+
* @class MSIDBoundRefreshTokenCacheItem
30+
* @brief Represents a bound refresh token cache item that is bound to the device.
31+
*/
32+
@interface MSIDBoundRefreshTokenCacheItem : MSIDCredentialCacheItem <NSSecureCoding>
33+
34+
/**
35+
* @property boundDeviceId
36+
* @brief The unique identifier of the device to which the refresh token is bound.
37+
*/
38+
@property (atomic) NSString *boundDeviceId;
39+
40+
@property (nonatomic, readonly) NSString *boundRefreshToken;
41+
42+
@end
Lines changed: 145 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,145 @@
1+
//
2+
// Copyright (c) Microsoft Corporation.
3+
// All rights reserved.
4+
//
5+
// This code is licensed under the MIT License.
6+
//
7+
// Permission is hereby granted, free of charge, to any person obtaining a copy
8+
// of this software and associated documentation files(the "Software"), to deal
9+
// in the Software without restriction, including without limitation the rights
10+
// to use, copy, modify, merge, publish, distribute, sublicense, and / or sell
11+
// copies of the Software, and to permit persons to whom the Software is
12+
// furnished to do so, subject to the following conditions :
13+
//
14+
// The above copyright notice and this permission notice shall be included in
15+
// all copies or substantial portions of the Software.
16+
//
17+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23+
// THE SOFTWARE.
24+
25+
#import "MSIDBoundRefreshTokenCacheItem.h"
26+
#import "NSString+MSIDExtensions.h"
27+
#import "NSData+MSIDExtensions.h"
28+
29+
@implementation MSIDBoundRefreshTokenCacheItem
30+
31+
- (NSString *)boundRefreshToken
32+
{
33+
return self.secret;
34+
}
35+
36+
#pragma mark - NSSecureCoding
37+
38+
+ (BOOL)supportsSecureCoding
39+
{
40+
return YES;
41+
}
42+
43+
- (void)encodeWithCoder:(NSCoder *)coder
44+
{
45+
[coder encodeObject:[self jsonDictionary] forKey:@"cacheItem"];
46+
}
47+
48+
- (id)initWithCoder:(NSCoder *)decoder
49+
{
50+
if (!(self = [super init]))
51+
{
52+
return nil;
53+
}
54+
NSDictionary *json = [decoder decodeObjectOfClass:[NSDictionary class] forKey:@"cacheItem"];
55+
if (json)
56+
{
57+
self = [self initWithJSONDictionary:json error:nil];
58+
}
59+
return self;
60+
}
61+
62+
#pragma mark - MSIDJsonSerializable
63+
64+
- (instancetype)initWithJSONDictionary:(NSDictionary *)json error:(NSError *__autoreleasing*)error
65+
{
66+
if (!(self = [super initWithJSONDictionary:json error:error]))
67+
{
68+
return nil;
69+
}
70+
71+
if (!self.secret)
72+
{
73+
if (error) *error = MSIDCreateError(MSIDErrorDomain, MSIDErrorInvalidInternalParameter, @"Couldn't read bound refresh token.", nil, nil, nil, nil, nil, YES);
74+
return nil;
75+
}
76+
77+
_boundDeviceId = [json msidObjectForKey:MSID_BOUND_DEVICE_ID_CACHE_KEY ofClass:[NSString class]];
78+
if (!_boundDeviceId)
79+
{
80+
if (error) *error = MSIDCreateError(MSIDErrorDomain, MSIDErrorInvalidInternalParameter, @"Bound device ID is nil. Cannot initialize bound refresh token cache item without bound device id", nil, nil, nil, nil, nil, YES);
81+
return nil;
82+
}
83+
84+
return self;
85+
}
86+
87+
- (NSDictionary *)jsonDictionary
88+
{
89+
NSMutableDictionary *dictionary = [[super jsonDictionary] mutableCopy];
90+
91+
if (!dictionary)
92+
{
93+
dictionary = [NSMutableDictionary new];
94+
}
95+
96+
dictionary[MSID_BOUND_DEVICE_ID_CACHE_KEY] = self.boundDeviceId;
97+
return dictionary;
98+
}
99+
100+
#pragma mark - NSObject
101+
102+
- (BOOL)isEqual:(id)object
103+
{
104+
if (self == object)
105+
{
106+
return YES;
107+
}
108+
109+
if (![object isKindOfClass:self.class])
110+
{
111+
return NO;
112+
}
113+
114+
return [self isEqualToItem:(MSIDBoundRefreshTokenCacheItem *)object];
115+
}
116+
117+
- (BOOL)isEqualToItem:(MSIDBoundRefreshTokenCacheItem *)item
118+
{
119+
BOOL result = [super isEqualToItem:item];
120+
result &= (!self.boundDeviceId && !item.boundDeviceId) || [self.boundDeviceId isEqualToString:item.boundDeviceId];
121+
return result;
122+
}
123+
124+
- (NSUInteger)hash
125+
{
126+
NSUInteger hash = [super hash];
127+
hash = hash * 31 + self.boundDeviceId.hash;
128+
return hash;
129+
}
130+
131+
- (NSString *)description
132+
{
133+
NSString *baseDescription = [super description];
134+
return [NSString stringWithFormat:@"%@, boundDeviceId: %@", baseDescription, self.boundDeviceId ? self.boundDeviceId : @"<nil>"];
135+
}
136+
137+
#pragma mark - NSCopying
138+
139+
- (id)copyWithZone:(NSZone *)zone
140+
{
141+
MSIDBoundRefreshTokenCacheItem *item = (MSIDBoundRefreshTokenCacheItem *)[super copyWithZone:zone];
142+
item.boundDeviceId = [self.boundDeviceId copyWithZone:zone];
143+
return item;
144+
}
145+
@end

IdentityCore/src/cache/token/MSIDCredentialCacheItem+MSIDBaseToken.m

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
#import "MSIDFamilyRefreshToken.h"
3535
#import "MSIDV1IdToken.h"
3636
#import "MSIDAccessTokenWithAuthScheme.h"
37+
#import "MSIDBoundRefreshToken.h"
3738

3839
@implementation MSIDCredentialCacheItem (MSIDBaseToken)
3940

@@ -73,6 +74,10 @@ - (MSIDBaseToken *)tokenWithType:(MSIDCredentialType)credentialType
7374
{
7475
return [[MSIDFamilyRefreshToken alloc] initWithTokenCacheItem:self];
7576
}
77+
case MSIDBoundRefreshTokenType:
78+
{
79+
return [[MSIDBoundRefreshToken alloc] initWithTokenCacheItem:self];
80+
}
7681
default:
7782
return [[MSIDBaseToken alloc] initWithTokenCacheItem:self];
7883
}

0 commit comments

Comments
 (0)