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

SDK: Refresh Token implementation #1319

Merged
merged 21 commits into from
Jan 31, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
43a8858
First pass at refresh token support using existing httpClient token r…
langleyd Dec 9, 2021
34fe5dd
Move HTTPClient to pull in access token vs hold a reference. Use disp…
langleyd Dec 13, 2021
79d101f
Update http refresh mechanism naming and documentation to more accura…
langleyd Dec 13, 2021
360c056
Add preemptive expiry
langleyd Dec 15, 2021
9ad4f77
Add token persistence handler to syncrhonize token data access from d…
langleyd Jan 6, 2022
3589712
Merge branch 'develop' of github.com:matrix-org/matrix-ios-sdk into l…
langleyd Jan 6, 2022
e280c4c
Improve error handling.
langleyd Jan 10, 2022
ced463c
Fix tests.
langleyd Jan 10, 2022
7465d4d
Fix MXCredentials equality
langleyd Jan 11, 2022
8977baa
Add softLogout and refreshTokenAuth to callback for analytics
langleyd Jan 13, 2022
9dc2771
Merge branch 'develop' of github.com:matrix-org/matrix-ios-sdk into l…
langleyd Jan 14, 2022
7da1e08
Update MXCoreDataRoomListDataManagerUnitTests.swift
langleyd Jan 14, 2022
634b47c
Fix preemptive refresh code (had changed to debug errors)
langleyd Jan 14, 2022
8e8bb79
Fix one case where refresh token might not be persisted if RestClient…
langleyd Jan 24, 2022
35fa763
Merge branch 'develop' of github.com:matrix-org/matrix-ios-sdk into l…
langleyd Jan 24, 2022
98c2efd
Fix naming of `expiresInMs` in `MXRefreshTokenData` and the logic to …
langleyd Jan 24, 2022
b9cbc3b
Make MXRefreshTokenData readonly
langleyd Jan 24, 2022
7e44b4d
Api cleanup.
langleyd Jan 28, 2022
60902b8
Move MXRefreshResponse to it's own file.
langleyd Jan 28, 2022
fa0d781
put back nil equality check
langleyd Jan 28, 2022
4660b34
Fix nullability of refresh response.
langleyd Jan 30, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions MatrixSDK.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -697,6 +697,8 @@
3AF85F9226FC7AE800A9E67B /* MXSpaceNotificationState.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3AF85F9126FC7AE800A9E67B /* MXSpaceNotificationState.swift */; };
3AF85F9326FC7AE800A9E67B /* MXSpaceNotificationState.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3AF85F9126FC7AE800A9E67B /* MXSpaceNotificationState.swift */; };
3B60DCAB92D470B91262BF0C /* libPods-MatrixSDKTests-macOS.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 15D7F292D95EB58AEE801C4E /* libPods-MatrixSDKTests-macOS.a */; };
66398BA527A4085B00466E89 /* MXRefreshResponse.m in Sources */ = {isa = PBXBuildFile; fileRef = 66398BA427A4085B00466E89 /* MXRefreshResponse.m */; };
66398BA627A4085B00466E89 /* MXRefreshResponse.m in Sources */ = {isa = PBXBuildFile; fileRef = 66398BA427A4085B00466E89 /* MXRefreshResponse.m */; };
66AC9D23278CE627002E9B8F /* MXRefreshTokenData.h in Headers */ = {isa = PBXBuildFile; fileRef = 66AC9D21278CE626002E9B8F /* MXRefreshTokenData.h */; };
66AC9D24278CE627002E9B8F /* MXRefreshTokenData.h in Headers */ = {isa = PBXBuildFile; fileRef = 66AC9D21278CE626002E9B8F /* MXRefreshTokenData.h */; };
66AC9D25278CE627002E9B8F /* MXRefreshTokenData.m in Sources */ = {isa = PBXBuildFile; fileRef = 66AC9D22278CE626002E9B8F /* MXRefreshTokenData.m */; };
Expand Down Expand Up @@ -2243,6 +2245,8 @@
3AF85F9126FC7AE800A9E67B /* MXSpaceNotificationState.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MXSpaceNotificationState.swift; sourceTree = "<group>"; };
492C3485159D57C2116EDCBD /* Pods-SDK-MatrixSDK-macOS.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-SDK-MatrixSDK-macOS.debug.xcconfig"; path = "Target Support Files/Pods-SDK-MatrixSDK-macOS/Pods-SDK-MatrixSDK-macOS.debug.xcconfig"; sourceTree = "<group>"; };
6257D945D115DA658F44E8D4 /* Pods-SDK-MatrixSDK-macOS.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-SDK-MatrixSDK-macOS.release.xcconfig"; path = "Target Support Files/Pods-SDK-MatrixSDK-macOS/Pods-SDK-MatrixSDK-macOS.release.xcconfig"; sourceTree = "<group>"; };
66398BA427A4085B00466E89 /* MXRefreshResponse.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = MXRefreshResponse.m; sourceTree = "<group>"; };
66398BA727A408C000466E89 /* MXRefreshResponse.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MXRefreshResponse.h; sourceTree = "<group>"; };
66AC9D21278CE626002E9B8F /* MXRefreshTokenData.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MXRefreshTokenData.h; sourceTree = "<group>"; };
66AC9D22278CE626002E9B8F /* MXRefreshTokenData.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MXRefreshTokenData.m; sourceTree = "<group>"; };
6869D206EA7C7FB05EAB75B0 /* Pods-MatrixSDKTests-iOS.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-MatrixSDKTests-iOS.release.xcconfig"; path = "Target Support Files/Pods-MatrixSDKTests-iOS/Pods-MatrixSDKTests-iOS.release.xcconfig"; sourceTree = "<group>"; };
Expand Down Expand Up @@ -3368,6 +3372,8 @@
B14EECD42577DE4400448735 /* Login */,
3281E8B319E42DFE00976E1A /* MXJSONModel.h */,
3281E8B419E42DFE00976E1A /* MXJSONModel.m */,
66398BA727A408C000466E89 /* MXRefreshResponse.h */,
66398BA427A4085B00466E89 /* MXRefreshResponse.m */,
3281E8B519E42DFE00976E1A /* MXJSONModels.h */,
3281E8B619E42DFE00976E1A /* MXJSONModels.m */,
323E0C591A306D7A00A31D73 /* MXEvent.h */,
Expand Down Expand Up @@ -5565,6 +5571,7 @@
F03EF4FF1DF014D9009DF592 /* MXMediaLoader.m in Sources */,
320A8841217F4E3F002EA952 /* MXMegolmBackupAuthData.m in Sources */,
B1A0270226162110001AADFF /* MXSpaceChildrenResponse.m in Sources */,
66398BA527A4085B00466E89 /* MXRefreshResponse.m in Sources */,
327E9AF72289D53800A98BC1 /* MXReactionCount.m in Sources */,
32FFB4F1217E146A00C96002 /* MXRecoveryKey.m in Sources */,
32DC15D51A8CF874006F9AD3 /* MXPushRuleEventMatchConditionChecker.m in Sources */,
Expand Down Expand Up @@ -6055,6 +6062,7 @@
B14EF1DF2397E90400758AF0 /* MXAggregatedEditsUpdater.m in Sources */,
B14EF1E02397E90400758AF0 /* MXRealmCryptoStore.m in Sources */,
B14EF1E12397E90400758AF0 /* MXRoomSummary.m in Sources */,
66398BA627A4085B00466E89 /* MXRefreshResponse.m in Sources */,
B14EF1E22397E90400758AF0 /* MXPushRuleRoomMemberCountConditionChecker.m in Sources */,
B14EF1E32397E90400758AF0 /* MXCall.m in Sources */,
B14EF1E42397E90400758AF0 /* MXWellknownIntegrations.m in Sources */,
Expand Down
21 changes: 0 additions & 21 deletions MatrixSDK/JSONModels/MXJSONModels.h
Original file line number Diff line number Diff line change
Expand Up @@ -244,27 +244,6 @@ FOUNDATION_EXPORT NSString *const kMXLoginIdentifierTypePhone;

@end

/**
`MXRefreshResponse` represents the response to an auth refresh request.
*/
@interface MXRefreshResponse : MXJSONModel
/**
The access token to create a MXRestClient
*/
@property (nonatomic) NSString *accessToken;

/**
The lifetime in milliseconds of the access token. (optional)
*/
@property (nonatomic) uint64_t expiresInMs;

/**
The refresh token, which can be used to obtain new access tokens. (optional)
*/
@property (nonatomic) NSString *refreshToken;

@end

/**
`MXThirdPartyIdentifier` represents the response to /account/3pid GET request.
*/
Expand Down
17 changes: 0 additions & 17 deletions MatrixSDK/JSONModels/MXJSONModels.m
Original file line number Diff line number Diff line change
Expand Up @@ -223,23 +223,6 @@ + (id)modelFromJSON:(NSDictionary *)JSONDictionary

@end

@implementation MXRefreshResponse

+ (id)modelFromJSON:(NSDictionary *)JSONDictionary
{
MXRefreshResponse *refreshResponse = [[MXRefreshResponse alloc] init];
if (refreshResponse)
{
MXJSONModelSetString(refreshResponse.accessToken, JSONDictionary[@"access_token"]);
MXJSONModelSetUInt64(refreshResponse.expiresInMs, JSONDictionary[@"expires_in_ms"]);
MXJSONModelSetString(refreshResponse.refreshToken, JSONDictionary[@"refresh_token"]);
}

return refreshResponse;
}

@end

@implementation MXThirdPartyIdentifier

+ (id)modelFromJSON:(NSDictionary *)JSONDictionary
Expand Down
38 changes: 38 additions & 0 deletions MatrixSDK/JSONModels/MXRefreshResponse.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
//
// Copyright 2021 The Matrix.org Foundation C.I.C
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//

#import "MXJSONModel.h"

/**
`MXRefreshResponse` represents the response to an auth refresh request.
*/
@interface MXRefreshResponse : MXJSONModel
langleyd marked this conversation as resolved.
Show resolved Hide resolved
/**
The access token to create a MXRestClient
*/
@property (nonatomic) NSString *accessToken;

/**
The lifetime in milliseconds of the access token. (optional)
*/
@property (nonatomic) uint64_t expiresInMs;

/**
The refresh token, which can be used to obtain new access tokens. (optional)
*/
@property (nonatomic) NSString *refreshToken;

@end
35 changes: 35 additions & 0 deletions MatrixSDK/JSONModels/MXRefreshResponse.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
//
// Copyright 2021 The Matrix.org Foundation C.I.C
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//

#import <Foundation/Foundation.h>
#import "MXRefreshResponse.h"

@implementation MXRefreshResponse

+ (id)modelFromJSON:(NSDictionary *)JSONDictionary
{
MXRefreshResponse *refreshResponse = [[MXRefreshResponse alloc] init];
if (refreshResponse)
{
MXJSONModelSetString(refreshResponse.accessToken, JSONDictionary[@"access_token"]);
MXJSONModelSetUInt64(refreshResponse.expiresInMs, JSONDictionary[@"expires_in_ms"]);
MXJSONModelSetString(refreshResponse.refreshToken, JSONDictionary[@"refresh_token"]);
}

return refreshResponse;
}

@end
1 change: 1 addition & 0 deletions MatrixSDK/MXRestClient.m
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

#import "MXSDKOptions.h"
#import "MXJSONModel.h"
#import "MXRefreshResponse.h"
#import "MXTools.h"
#import "MXError.h"

Expand Down