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

Implement social login #3890

Merged
merged 31 commits into from
Jan 8, 2021
Merged
Show file tree
Hide file tree
Changes from 30 commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
a96607b
Social login: Add social login buttons assets.
SBiOSoftWhare Dec 16, 2020
ae1e0ea
Social login: Add SocialLoginButton that represents a button associat…
SBiOSoftWhare Dec 16, 2020
a47e277
UIImage: Add convenient method to resize an image.
SBiOSoftWhare Dec 16, 2020
71b1e11
Add SourceImage that represents a local or remote image.
SBiOSoftWhare Dec 16, 2020
bbe0cad
Theme: Introduce ThemeIdentifier to make theme identification easier …
SBiOSoftWhare Dec 16, 2020
fee62af
Social login: Add SocialLoginButtonFactory that builds SocialLoginBut…
SBiOSoftWhare Dec 17, 2020
c25add9
Social login: Add strings.
SBiOSoftWhare Dec 17, 2020
5c60f83
Social login: Add SocialLoginListView displays a list of social login…
SBiOSoftWhare Dec 17, 2020
577a0ee
AuthVC: Support both password and social login display.
SBiOSoftWhare Dec 17, 2020
f8bbcc4
SocialLoginListView: Remove debug background.
SBiOSoftWhare Dec 17, 2020
58c811c
Handle custom scheme URL
SBiOSoftWhare Dec 18, 2020
5231ec1
Add SSOAuthenticationService
SBiOSoftWhare Dec 18, 2020
baaf926
SSO authentication: Abstract and support both SFAuthenticationSession…
SBiOSoftWhare Dec 18, 2020
d83eecc
Add SSOAuthenticationPresenter enables to present single sign-on auth…
SBiOSoftWhare Dec 18, 2020
1f9ba64
AuthVC: Handle SSO authentication.
SBiOSoftWhare Dec 18, 2020
2cea584
Update pbxproj
SBiOSoftWhare Dec 18, 2020
81a3e1d
Fix pbxproj.
SBiOSoftWhare Jan 5, 2021
1fb17c7
Add convenient methods on URLComponents.
SBiOSoftWhare Jan 7, 2021
860d9b0
Introduce DeepLinkOption that represents deep link paths with their r…
SBiOSoftWhare Jan 7, 2021
3edbf37
Add CustomSchemeURLParser that enables to parse custom scheme URL and…
SBiOSoftWhare Jan 7, 2021
54cfca2
SSOAuthenticationService: Update callback scheme property and handle …
SBiOSoftWhare Jan 7, 2021
3c2ea1e
SSO: Handle transaction id in AuthVC and SSOAuthenticationPresenter.
SBiOSoftWhare Jan 7, 2021
8623f34
AppCoordinator: Handle custom scheme URL parsing and SSO deep link.
SBiOSoftWhare Jan 7, 2021
80b33cc
Update pbxproj.
SBiOSoftWhare Jan 7, 2021
f12fe6c
AuthVC: Do use fallback page when using SSO without idp.
SBiOSoftWhare Jan 7, 2021
984e078
Update changes
SBiOSoftWhare Jan 7, 2021
68f4bcf
Update Riot/Categories/UIImage.swift
SBiOSoftWhare Jan 8, 2021
ffbdd80
Update SocialLoginButton.
SBiOSoftWhare Jan 8, 2021
5a5122a
Fix typo in SSOURLConstants.
SBiOSoftWhare Jan 8, 2021
3f3a067
Fix typo with SSO authentication completion handler type alias.
SBiOSoftWhare Jan 8, 2021
b77ec3e
Merge branch 'develop' into element_3846
SBiOSoftWhare Jan 8, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ Changes to be released in next version
=================================================

✨ Features
*
* AuthVC: Add social login (#3846).

🙌 Improvements
*
* AuthVC: SSO authentication now use redirect URL instead of fallback page (#3846).

🐛 Bugfix
*
Expand Down
11 changes: 11 additions & 0 deletions Config/BuildSettings.swift
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,17 @@ final class BuildSettings: NSObject {
return keychainAccessGroup
}

static var applicationURLScheme: String? {
guard let urlTypes = Bundle.app.object(forInfoDictionaryKey: "CFBundleURLTypes") as? [AnyObject],
let urlTypeDictionary = urlTypes.first as? [String: AnyObject],
let urlSchemes = urlTypeDictionary["CFBundleURLSchemes"] as? [AnyObject],
let externalURLScheme = urlSchemes.first as? String else {
return nil
}

return externalURLScheme
}

static var pushKitAppIdProd: String {
return baseBundleIdentifier + ".ios.voip.prod"
}
Expand Down
2 changes: 2 additions & 0 deletions Config/Common.xcconfig
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,5 @@ KEYCHAIN_ACCESS_GROUP = $(AppIdentifierPrefix)$(BASE_BUNDLE_IDENTIFIER).keychain

//Make Xcode 12 and fastlane(xcodebuild) happy while some pods are not updated
EXCLUDED_ARCHS[sdk=iphonesimulator*] = arm64

APPLICATION_SCHEME = element
108 changes: 107 additions & 1 deletion Riot.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

6 changes: 6 additions & 0 deletions Riot/Assets/Images.xcassets/Authentication/Contents.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"info" : {
"author" : "xcode",
"version" : 1
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"info" : {
"author" : "xcode",
"version" : 1
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"images" : [
{
"filename" : "social_login_button_apple.png",
"idiom" : "universal",
"scale" : "1x"
},
{
"filename" : "social_login_button_apple@2x.png",
"idiom" : "universal",
"scale" : "2x"
},
{
"filename" : "social_login_button_apple@3x.png",
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"images" : [
{
"filename" : "social_login_button_facebook.png",
"idiom" : "universal",
"scale" : "1x"
},
{
"filename" : "social_login_button_facebook@2x.png",
"idiom" : "universal",
"scale" : "2x"
},
{
"filename" : "social_login_button_facebook@3x.png",
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"images" : [
{
"filename" : "social_login_button_github.png",
"idiom" : "universal",
"scale" : "1x"
},
{
"filename" : "social_login_button_github@2x.png",
"idiom" : "universal",
"scale" : "2x"
},
{
"filename" : "social_login_button_github@3x.png",
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"images" : [
{
"filename" : "social_login_button_google.png",
"idiom" : "universal",
"scale" : "1x"
},
{
"filename" : "social_login_button_google@2x.png",
"idiom" : "universal",
"scale" : "2x"
},
{
"filename" : "social_login_button_google@3x.png",
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"images" : [
{
"filename" : "social_login_button_twitter.png",
"idiom" : "universal",
"scale" : "1x"
},
{
"filename" : "social_login_button_twitter@2x.png",
"idiom" : "universal",
"scale" : "2x"
},
{
"filename" : "social_login_button_twitter@3x.png",
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 10 additions & 0 deletions Riot/Assets/en.lproj/Vector.strings
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,16 @@
"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";

// Social login

"social_login_list_title_continue" = "Continue with";
"social_login_list_title_sign_in" = "Or login with";
"social_login_list_title_sign_up" = "Or register with";

"social_login_button_title_continue" = "Continue with %@";
"social_login_button_title_sign_in" = "Sign In with %@";
"social_login_button_title_sign_up" = "Sign Up with %@";

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

Expand Down
25 changes: 25 additions & 0 deletions Riot/Categories/UIImage.swift
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,31 @@ extension UIImage {
return newImage
}

// Based on https://stackoverflow.com/a/31314494
@objc func vc_resized(with targetSize: CGSize) -> UIImage? {
let size = self.size

let widthRatio = targetSize.width/size.width
let heightRatio = targetSize.height/size.height

// Figure out what our orientation is, and use that to form the rectangle
let newSize: CGSize
if widthRatio > heightRatio {
newSize = CGSize(width: size.width * heightRatio, height: size.height * heightRatio)
} else {
newSize = CGSize(width: size.width * widthRatio, height: size.height * widthRatio)
}

let rect = CGRect(origin: .zero, size: newSize)

UIGraphicsBeginImageContextWithOptions(newSize, false, 0)
draw(in: rect)
let newImage = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()

return newImage
}

@objc func vc_notRenderedImage() -> UIImage {
if let cgImage = cgImage {
return NotRenderedImage(cgImage: cgImage, scale: UIScreen.main.scale, orientation: .up)
Expand Down
28 changes: 28 additions & 0 deletions Riot/Categories/URLComponents.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
//
// Copyright 2020 New Vector Ltd
//
// 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

extension URLComponents {

func vc_getQueryItem(with name: String) -> URLQueryItem? {
return self.queryItems?.first(where: { $0.name == name })
}

func vc_getQueryItemValue(for name: String) -> String? {
return self.vc_getQueryItem(with: name)?.value
}
}
5 changes: 5 additions & 0 deletions Riot/Generated/Images.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ internal typealias AssetImageTypeAlias = ImageAsset.Image
// swiftlint:disable identifier_name line_length nesting type_body_length type_name
internal enum Asset {
internal enum Images {
internal static let socialLoginButtonApple = ImageAsset(name: "social_login_button_apple")
internal static let socialLoginButtonFacebook = ImageAsset(name: "social_login_button_facebook")
internal static let socialLoginButtonGithub = ImageAsset(name: "social_login_button_github")
internal static let socialLoginButtonGoogle = ImageAsset(name: "social_login_button_google")
internal static let socialLoginButtonTwitter = ImageAsset(name: "social_login_button_twitter")
internal static let callAudioMuteOffIcon = ImageAsset(name: "call_audio_mute_off_icon")
internal static let callAudioMuteOnIcon = ImageAsset(name: "call_audio_mute_on_icon")
internal static let callChatIcon = ImageAsset(name: "call_chat_icon")
Expand Down
24 changes: 24 additions & 0 deletions Riot/Generated/Strings.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4266,6 +4266,30 @@ internal enum VectorL10n {
internal static var skip: String {
return VectorL10n.tr("Vector", "skip")
}
/// Continue with %@
internal static func socialLoginButtonTitleContinue(_ p1: String) -> String {
return VectorL10n.tr("Vector", "social_login_button_title_continue", p1)
}
/// Sign In with %@
internal static func socialLoginButtonTitleSignIn(_ p1: String) -> String {
return VectorL10n.tr("Vector", "social_login_button_title_sign_in", p1)
}
/// Sign Up with %@
internal static func socialLoginButtonTitleSignUp(_ p1: String) -> String {
return VectorL10n.tr("Vector", "social_login_button_title_sign_up", p1)
}
/// Continue with
internal static var socialLoginListTitleContinue: String {
return VectorL10n.tr("Vector", "social_login_list_title_continue")
}
/// Or login with
internal static var socialLoginListTitleSignIn: String {
return VectorL10n.tr("Vector", "social_login_list_title_sign_in")
}
/// Or register with
internal static var socialLoginListTitleSignUp: String {
return VectorL10n.tr("Vector", "social_login_list_title_sign_up")
}
/// Start
internal static var start: String {
return VectorL10n.tr("Vector", "start")
Expand Down
36 changes: 36 additions & 0 deletions Riot/Managers/Theme/ThemeIdentifier.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
//
// Copyright 2020 New Vector Ltd
//
// 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

enum ThemeIdentifier: String, RawRepresentable {
case light = "default"
case dark = "dark"
case black = "black"

init?(rawValue: String) {
switch rawValue {
case "default":
self = .light
case "dark":
self = .dark
case "black":
self = .black
default:
return nil
}
}
}
27 changes: 27 additions & 0 deletions Riot/Managers/Theme/ThemeService.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
//
// Copyright 2020 New Vector Ltd
//
// 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

extension ThemeService {

var themeIdentifier: ThemeIdentifier? {
guard let themeId = self.themeId else {
return nil
}
return ThemeIdentifier(rawValue: themeId)
}
}
2 changes: 1 addition & 1 deletion Riot/Managers/Theme/Themes/BlackTheme.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class BlackTheme: DarkTheme {

override init() {
super.init()
self.identifier = "black"
self.identifier = ThemeIdentifier.black.rawValue
self.backgroundColor = UIColor(rgb: 0x000000)
self.baseColor = UIColor(rgb: 0x000000)
self.headerBackgroundColor = UIColor(rgb: 0x000000)
Expand Down
2 changes: 1 addition & 1 deletion Riot/Managers/Theme/Themes/DarkTheme.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import UIKit
@objcMembers
class DarkTheme: NSObject, Theme {

var identifier: String = "dark"
var identifier: String = ThemeIdentifier.dark.rawValue

var backgroundColor: UIColor = UIColor(rgb: 0x15191E)

Expand Down
2 changes: 1 addition & 1 deletion Riot/Managers/Theme/Themes/DefaultTheme.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import UIKit
@objcMembers
class DefaultTheme: NSObject, Theme {

var identifier: String = "default"
var identifier: String = ThemeIdentifier.light.rawValue

var backgroundColor: UIColor = UIColor(rgb: 0xFFFFFF)

Expand Down