Skip to content

Commit

Permalink
Finish riot_2703
Browse files Browse the repository at this point in the history
  • Loading branch information
manuroe committed Sep 10, 2019
2 parents 5a30474 + 4ffe0bd commit 9ab4dd6
Show file tree
Hide file tree
Showing 9 changed files with 165 additions and 6 deletions.
7 changes: 7 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
Changes in 0.9.3 (2019-09-10)
===============================================

Improvements:
* Support Riot configuration link to customise HS and IS (#2703).
* Authentication: Create a way to filter and prioritise flows (with handleSupportedFlowsInAuthenticationSession).

Changes in 0.9.2 (2019-08-08)
===============================================

Expand Down
92 changes: 92 additions & 0 deletions Riot/AppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -2100,6 +2100,11 @@ - (BOOL)handleUniversalLink:(NSUserActivity*)userActivity

// iOS Patch: fix vector.im urls before using it
webURL = [Tools fixURLWithSeveralHashKeys:webURL];

if ([webURL.path hasPrefix:@"/config"])
{
return [self handleServerProvionningLink:webURL];
}

// Manage email validation link
if ([webURL.path isEqualToString:@"/_matrix/identity/api/v1/validate/email/submitToken"])
Expand Down Expand Up @@ -2547,6 +2552,93 @@ - (void)parseUniversalLinkFragment:(NSString*)fragment outPathParams:(NSArray<NS
*outQueryParams = queryParams;
}


- (BOOL)handleServerProvionningLink:(NSURL*)link
{
NSLog(@"[AppDelegate] handleServerProvionningLink: %@", link);

NSString *homeserver, *identityServer;
[self parseServerProvionningLink:link homeserver:&homeserver identityServer:&identityServer];

if (homeserver)
{
if ([MXKAccountManager sharedManager].activeAccounts.count)
{
[self displayServerProvionningLinkBuyAlreadyLoggedInAlertWithCompletion:^(BOOL logout) {

NSLog(@"[AppDelegate] handleServerProvionningLink: logoutWithConfirmation: logout: %@", @(logout));
if (logout)
{
[self logoutWithConfirmation:NO completion:^(BOOL isLoggedOut) {
[self handleServerProvionningLink:link];
}];
}
}];
}
else
{
[_masterTabBarController showAuthenticationScreen];
[_masterTabBarController.authViewController showCustomHomeserver:homeserver andIdentityServer:identityServer];
}

return YES;
}

return NO;
}

- (void)parseServerProvionningLink:(NSURL*)link homeserver:(NSString**)homeserver identityServer:(NSString**)identityServer
{
if ([link.path isEqualToString:@"/config/config"])
{
NSURLComponents *linkURLComponents = [NSURLComponents componentsWithURL:link resolvingAgainstBaseURL:NO];
for (NSURLQueryItem *item in linkURLComponents.queryItems)
{
if ([item.name isEqualToString:@"hs_url"])
{
*homeserver = item.value;
}
else if ([item.name isEqualToString:@"is_url"])
{
*identityServer = item.value;
break;
}
}
}
else
{
NSLog(@"[AppDelegate] parseServerProvionningLink: Error: Unknown path: %@", link.path);
}


NSLog(@"[AppDelegate] parseServerProvionningLink: homeserver: %@ - identityServer: %@", *homeserver, *identityServer);
}

- (void)displayServerProvionningLinkBuyAlreadyLoggedInAlertWithCompletion:(void (^)(BOOL logout))completion
{
// Ask confirmation
self.logoutConfirmation = [UIAlertController alertControllerWithTitle:NSLocalizedStringFromTable(@"error_user_already_logged_in", @"Vector", nil) message:nil preferredStyle:UIAlertControllerStyleAlert];

[self.logoutConfirmation addAction:[UIAlertAction actionWithTitle:NSLocalizedStringFromTable(@"settings_sign_out", @"Vector", nil)
style:UIAlertActionStyleDefault
handler:^(UIAlertAction * action)
{
self.logoutConfirmation = nil;
completion(YES);
}]];

[self.logoutConfirmation addAction:[UIAlertAction actionWithTitle:[NSBundle mxk_localizedStringForKey:@"cancel"]
style:UIAlertActionStyleCancel
handler:^(UIAlertAction * action)
{
self.logoutConfirmation = nil;
completion(NO);
}]];

[self.logoutConfirmation mxk_setAccessibilityIdentifier: @"AppDelegateLogoutConfirmationAlert"];
[self showNotificationAlert:self.logoutConfirmation];
}

#pragma mark - Matrix sessions handling

- (void)initMatrixSessions
Expand Down
2 changes: 2 additions & 0 deletions Riot/Assets/en.lproj/Vector.strings
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,8 @@
"auth_softlogout_clear_data_sign_out_msg" = "Are you sure you want to clear all data currently stored on this device? Sign in again to access your account data and messages.";
"auth_softlogout_clear_data_sign_out" = "Sign out";

// Errors
"error_user_already_logged_in" = "It looks like you’re trying to connect to another homeserver. Do you want to sign out?";

// Chat creation
"room_creation_title" = "New Chat";
Expand Down
4 changes: 4 additions & 0 deletions Riot/Generated/Strings.swift
Original file line number Diff line number Diff line change
Expand Up @@ -962,6 +962,10 @@ internal enum VectorL10n {
internal static var encryptedRoomMessageReplyToPlaceholder: String {
return VectorL10n.tr("Vector", "encrypted_room_message_reply_to_placeholder")
}
/// It looks like you’re trying to connect to another homeserver. Do you want to sign out?
internal static var errorUserAlreadyLoggedIn: String {
return VectorL10n.tr("Vector", "error_user_already_logged_in")
}
/// VoIP conference added by %@
internal static func eventFormatterJitsiWidgetAdded(_ p1: String) -> String {
return VectorL10n.tr("Vector", "event_formatter_jitsi_widget_added", p1)
Expand Down
2 changes: 2 additions & 0 deletions Riot/Modules/Authentication/AuthenticationViewController.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,5 +45,7 @@
@property (weak, nonatomic) IBOutlet UILabel *softLogoutClearDataLabel;
@property (weak, nonatomic) IBOutlet UIButton *softLogoutClearDataButton;

- (void)showCustomHomeserver:(NSString*)homeserver andIdentityServer:(NSString*)identityServer;

@end

52 changes: 52 additions & 0 deletions Riot/Modules/Authentication/AuthenticationViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -497,9 +497,61 @@ - (void)clearDataAfterSoftLogout
}];
}

/**
Filter and prioritise flows supported by the app.
@param authSession the auth session coming from the HS.
@return a new auth session
*/
- (MXAuthenticationSession*)handleSupportedFlowsInAuthenticationSession:(MXAuthenticationSession *)authSession
{
MXLoginFlow *ssoFlow;
NSMutableArray *supportedFlows = [NSMutableArray array];

for (MXLoginFlow *flow in authSession.flows)
{
// Remove known flows we do not support
if (![flow.type isEqualToString:kMXLoginFlowTypeToken])
{
NSLog(@"[AuthenticationVC] handleSupportedFlowsInAuthenticationSession: Filter out flow %@", flow.type);
[supportedFlows addObject:flow];
}

// Prioritise SSO over other flows
if ([flow.type isEqualToString:kMXLoginFlowTypeSSO]
|| [flow.type isEqualToString:kMXLoginFlowTypeCAS])
{
NSLog(@"[AuthenticationVC] handleSupportedFlowsInAuthenticationSession: Prioritise flow %@", flow.type);
ssoFlow = flow;
break;
}
}

if (ssoFlow)
{
[supportedFlows removeAllObjects];
[supportedFlows addObject:ssoFlow];
}

if (supportedFlows.count != authSession.flows.count)
{
MXAuthenticationSession *updatedAuthSession = [[MXAuthenticationSession alloc] init];
updatedAuthSession.session = authSession.session;
updatedAuthSession.params = authSession.params;
updatedAuthSession.flows = supportedFlows;
return updatedAuthSession;
}
else
{
return authSession;
}
}

- (void)handleAuthenticationSession:(MXAuthenticationSession *)authSession
{
// Make some cleaning from the server response according to what the app supports
authSession = [self handleSupportedFlowsInAuthenticationSession:authSession];

[super handleAuthenticationSession:authSession];

AuthInputsView *authInputsview;
Expand Down
4 changes: 2 additions & 2 deletions Riot/SupportingFiles/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>0.9.2</string>
<string>0.9.3</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>0.9.2</string>
<string>0.9.3</string>
<key>ITSAppUsesNonExemptEncryption</key>
<true/>
<key>ITSEncryptionExportComplianceCode</key>
Expand Down
4 changes: 2 additions & 2 deletions RiotShareExtension/SupportingFiles/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@
<key>CFBundlePackageType</key>
<string>XPC!</string>
<key>CFBundleShortVersionString</key>
<string>0.9.2</string>
<string>0.9.3</string>
<key>CFBundleVersion</key>
<string>0.9.2</string>
<string>0.9.3</string>
<key>NSExtension</key>
<dict>
<key>NSExtensionAttributes</key>
Expand Down
4 changes: 2 additions & 2 deletions SiriIntents/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@
<key>CFBundlePackageType</key>
<string>XPC!</string>
<key>CFBundleShortVersionString</key>
<string>0.9.2</string>
<string>0.9.3</string>
<key>CFBundleVersion</key>
<string>0.9.2</string>
<string>0.9.3</string>
<key>NSExtension</key>
<dict>
<key>NSExtensionAttributes</key>
Expand Down

0 comments on commit 9ab4dd6

Please sign in to comment.