Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
tal-mi committed Jul 31, 2024
2 parents 6017a06 + 1c38a4a commit b5a172c
Show file tree
Hide file tree
Showing 13 changed files with 181 additions and 129 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
# 1.0.7
1.0.7

* Updated Android core 7.1.0 - https://github.com/SAP/gigya-android-sdk/releases/tag/core-v7.1.0
* Updated Swift Core 1.7.0 - https://github.com/SAP/gigya-swift-sdk/releases/tag/core%2Fv1.7.0
* Please read each platform requirement changes for supporting social sign in.

# 1.0.6
1.0.6

Expand Down
2 changes: 1 addition & 1 deletion android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"

// Gigya SDK core implementation.
api 'com.sap.oss.gigya-android-sdk:sdk-core:7.0.+'
api 'com.sap.oss.gigya-android-sdk:sdk-core:7.1.+'
api 'com.github.SAP.gigya-android-sdk:sdk-auth:auth-v2.2.0'
api 'com.github.SAP.gigya-android-sdk:sdk-biometric:bio-v2.1.2'

Expand Down
6 changes: 3 additions & 3 deletions example/android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ apply plugin: 'kotlin-android'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"

android {
compileSdkVersion 33
compileSdkVersion 34

sourceSets {
main.java.srcDirs += 'src/main/kotlin'
Expand Down Expand Up @@ -87,7 +87,7 @@ dependencies {
implementation 'com.facebook.android:facebook-android-sdk:14.1.1'

// Google (Optional)
implementation 'com.google.android.gms:play-services-auth:20.5.0'

implementation 'androidx.credentials:credentials-play-services-auth:1.2.2'
implementation 'com.google.android.libraries.identity.googleid:googleid:1.1.0'

}
Original file line number Diff line number Diff line change
@@ -1,28 +1,34 @@
package com.sap.gigya_flutter_plugin_example.gigya.providers;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.os.CancellationSignal;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.content.ContextCompat;
import androidx.credentials.ClearCredentialStateRequest;
import androidx.credentials.Credential;
import androidx.credentials.CredentialManager;
import androidx.credentials.CredentialManagerCallback;
import androidx.credentials.GetCredentialRequest;
import androidx.credentials.GetCredentialResponse;
import androidx.credentials.exceptions.ClearCredentialException;
import androidx.credentials.exceptions.GetCredentialException;
import androidx.credentials.exceptions.NoCredentialException;

import com.sap.gigya_flutter_plugin_example.R;
import com.gigya.android.sdk.GigyaLogger;
import com.gigya.android.sdk.providers.external.IProviderWrapper;
import com.gigya.android.sdk.providers.external.IProviderWrapperCallback;
import com.gigya.android.sdk.providers.external.ProviderWrapper;
import com.gigya.android.sdk.ui.HostActivity;
import com.google.android.gms.auth.api.signin.GoogleSignIn;
import com.google.android.gms.auth.api.signin.GoogleSignInAccount;
import com.google.android.gms.auth.api.signin.GoogleSignInClient;
import com.google.android.gms.auth.api.signin.GoogleSignInOptions;
import com.google.android.gms.auth.api.signin.GoogleSignInStatusCodes;
import com.google.android.gms.common.api.ApiException;
import com.google.android.gms.tasks.Task;

import java.util.HashMap;
import com.google.android.libraries.identity.googleid.GetGoogleIdOption;
import com.google.android.libraries.identity.googleid.GoogleIdTokenCredential;

import java.util.Map;
import java.util.concurrent.Executor;

/**
* Google sign in wrapper class.
Expand All @@ -32,12 +38,18 @@
public class GoogleProviderWrapper extends ProviderWrapper implements IProviderWrapper {

private static final int RC_SIGN_IN = 0;
private GoogleSignInClient _googleClient;

private final CredentialManager _credentialsManager;

private final Executor _executor;

final Context context;

public GoogleProviderWrapper(Context context) {
super(context, R.string.google_client_id);
this.context = context;
_credentialsManager = CredentialManager.create(context);
_executor = ContextCompat.getMainExecutor(context);
}

@Override
Expand All @@ -46,80 +58,93 @@ public void login(Context context, final Map<String, Object> params, final IProv
callback.onFailed("Missing server client id. Check manifest implementation");
return;
}
GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
.requestServerAuthCode(pId)
.requestEmail()
.build();
_googleClient = GoogleSignIn.getClient(context, gso);

// Not using cached account. Server auth code can be used only once.
authenticate(params, callback);
authenticate(params, callback, true);
}

private void authenticate(final Map<String, Object> params, final IProviderWrapperCallback callback) {
private void handleSignIn(GetCredentialResponse getCredentialResponse, final Map<String, Object> params, final IProviderWrapperCallback callback) {
Credential credential = getCredentialResponse.getCredential();
if (credential.getType().equals(GoogleIdTokenCredential.TYPE_GOOGLE_ID_TOKEN_CREDENTIAL)) {
GoogleIdTokenCredential googleIdTokenCredential =
GoogleIdTokenCredential.createFrom(credential.getData());
params.put("idToken", googleIdTokenCredential.getIdToken());
callback.onLogin(params);
} else {
GigyaLogger.error("GoogleProviderWrapper", "Unexpected type of credential");
// ERROR.
callback.onFailed("Unexpected type of credential");
}
}

private void authenticate(final Map<String, Object> params,
final IProviderWrapperCallback callback,
boolean setFilterByAuthorizedAccounts) {
HostActivity.present(context, new HostActivity.HostActivityLifecycleCallbacks() {

@Override
public void onCreate(AppCompatActivity activity, @Nullable Bundle savedInstanceState) {
Intent signInIntent = _googleClient.getSignInIntent();
activity.startActivityForResult(signInIntent, RC_SIGN_IN);
}

@Override
public void onActivityResult(AppCompatActivity activity, int requestCode, int resultCode, @Nullable Intent data) {
if (requestCode == RC_SIGN_IN) {
Task<GoogleSignInAccount> task = GoogleSignIn.getSignedInAccountFromIntent(data);
handleSignInResult(params, activity, task, callback);
}
GetGoogleIdOption googleIdOption = new GetGoogleIdOption.Builder()
.setFilterByAuthorizedAccounts(setFilterByAuthorizedAccounts)
.setAutoSelectEnabled(true)
.setServerClientId(pId)
.build();

GetCredentialRequest request = new GetCredentialRequest.Builder()
.addCredentialOption(googleIdOption)
.build();

credentialsSignIn(activity, params, request, setFilterByAuthorizedAccounts, callback);
}
});
}

private void handleSignInResult(final Map<String, Object> loginParams, AppCompatActivity activity, Task<GoogleSignInAccount> completedTask, final IProviderWrapperCallback callback) {
try {
GoogleSignInAccount account = completedTask.getResult(ApiException.class);
if (account == null) {
callback.onFailed("Account unavailable");
} else {
/* Fetch server auth code */
final String authCode = account.getServerAuthCode();
if (authCode == null) {
callback.onFailed("Id token no available");
} else {
final Map<String, Object> loginMap = new HashMap<>();
loginMap.put("code", authCode);
callback.onLogin(loginMap);
private void credentialsSignIn(AppCompatActivity activity,
final Map<String, Object> params,
GetCredentialRequest request,
boolean setFilterByAuthorizedAccounts,
final IProviderWrapperCallback callback) {
_credentialsManager.getCredentialAsync(activity, request,
new CancellationSignal(),
_executor,
new CredentialManagerCallback<GetCredentialResponse, GetCredentialException>() {
@Override
public void onResult(GetCredentialResponse getCredentialResponse) {
handleSignIn(getCredentialResponse, params, callback);
activity.finish();
}

@Override
public void onError(@NonNull GetCredentialException e) {
GigyaLogger.debug("GoogleProviderWrapper", "login exception: " + e);
if (e instanceof NoCredentialException && setFilterByAuthorizedAccounts) {
authenticate(params, callback, false);
} else {
callback.onFailed(e.getLocalizedMessage());
activity.finish();
}
}
}
}
activity.finish();
} catch (ApiException e) {
final int exceptionStatusCode = e.getStatusCode();
switch (exceptionStatusCode) {
case GoogleSignInStatusCodes.SIGN_IN_CANCELLED:
callback.onCanceled();
break;
case GoogleSignInStatusCodes.SIGN_IN_FAILED:
default:
callback.onFailed(GoogleSignInStatusCodes.getStatusCodeString(exceptionStatusCode));
break;
}
activity.finish();
}
);
}

@Override
public void logout() {
if (_googleClient == null) {
if (pId == null) {
GigyaLogger.error("GoogleLoginProvider", "provider client id unavailable for logout");
return;
}
GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
.requestServerAuthCode(pId)
.requestEmail()
.build();
_googleClient = GoogleSignIn.getClient(context, gso);
}
_googleClient.signOut();
ClearCredentialStateRequest request = new ClearCredentialStateRequest();
_credentialsManager.clearCredentialStateAsync(request, new CancellationSignal(),
_executor,
new CredentialManagerCallback<Void, ClearCredentialException>() {
@Override
public void onResult(Void unused) {
GigyaLogger.debug("GoogleProviderWrapper", "logout success");
}

@Override
public void onError(@NonNull ClearCredentialException e) {
GigyaLogger.debug("GoogleProviderWrapper", "logout exception: " + e);
}
}
);
}

}
10 changes: 6 additions & 4 deletions example/ios/Runner/GigyaProviders/FacebookWrapper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,15 @@ import FBSDKCoreKit
import FBSDKLoginKit
import Gigya

// MARK: - for Gigya v1.7.0+

class FacebookWrapper: ProviderWrapperProtocol {

private var completionHandler: (_ jsonData: [String: Any]?, _ error: String?) -> Void = { _, _ in }

var clientID: String?

private let defaultReadPermissions = ["email"]
private let defaultReadPermissions = ["email", "user_birthday", "user_gender", "user_hometown", "user_location"]

lazy var fbLogin: LoginManager = {
return LoginManager()
Expand All @@ -33,16 +35,16 @@ class FacebookWrapper: ProviderWrapperProtocol {

fbLogin.logIn(permissions: defaultReadPermissions, from: viewController) { (result, error) in
if result?.isCancelled != false {
completion(nil, "cancelled")
completion(nil, "canceled")
return
}

if let error = error {
completion(nil, error.localizedDescription)
}

let jsonData: [String: Any] = ["accessToken": result?.token?.tokenString ?? "", "tokenExpiration": result?.token?.expirationDate.timeIntervalSince1970 ?? 0]

let jsonData: [String: Any] = ["authToken": result?.token?.tokenString ?? "", "idToken": result?.authenticationToken?.tokenString ?? "", "tokenExpiration": Int32(result?.token?.expirationDate.timeIntervalSince1970 ?? 0)]
completion(jsonData, nil)
}
}
Expand Down
14 changes: 8 additions & 6 deletions example/ios/Runner/GigyaProviders/GoogleWrapper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@
// GoogleWrapper.swift
// GigyaSwift
//
// Created by Shmuel, Sagi on 15/04/2019.
// Created by Shmuel, Sagi on 15/07/2023.
// Copyright © 2019 Gigya. All rights reserved.
//

import UIKit
import GoogleSignIn
import Gigya


// MARK: - Google Sign In V6 wrapper
// MARK: - for Gigya v1.7.0+
// MARK: - Google Sign In V7 wrapper

class GoogleWrapper: ProviderWrapperProtocol {
var clientID: String? = {
Expand All @@ -34,15 +34,17 @@ class GoogleWrapper: ProviderWrapperProtocol {

let signInConfig = GIDConfiguration.init(clientID: clientID, serverClientID: googleServerClientID)

GIDSignIn.sharedInstance.signIn(with: signInConfig, presenting: viewController) { user, error in
GIDSignIn.sharedInstance.configuration = signInConfig

GIDSignIn.sharedInstance.signIn(withPresenting: viewController) { user, error in
guard error == nil else {
completion(nil, error?.localizedDescription)
return
}

let jsonData: [String: Any] = ["idToken": user?.user.idToken?.tokenString ?? ""]

let jsonData = ["accessToken": user?.serverAuthCode ?? ""]
completion(jsonData, nil)

}
}

Expand Down
4 changes: 2 additions & 2 deletions example/lib/routes/login_with_credentials_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ class _LoginWithCredentialsPageState extends State<LoginWithCredentialsPage> {
return;
}

scaffoldState.showBottomSheet<void>(
scaffoldState.showBottomSheet(
(BuildContext context) => Material(
color: Colors.white,
elevation: 4,
Expand Down Expand Up @@ -276,7 +276,7 @@ class _LoginWithCredentialsPageState extends State<LoginWithCredentialsPage> {
return;
}

scaffoldState.showBottomSheet<void>(
scaffoldState.showBottomSheet(
(BuildContext context) => Material(
color: Colors.white,
elevation: 4,
Expand Down
2 changes: 1 addition & 1 deletion example/lib/routes/one_time_password_login_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ class _OneTimePasswordLoginPageState extends State<OneTimePasswordLoginPage> {
PendingOtpVerification verification,
String phone,
) {
_scaffoldKey.currentState?.showBottomSheet<void>((BuildContext context) {
_scaffoldKey.currentState?.showBottomSheet((BuildContext context) {
return Material(
color: Colors.white,
elevation: 4,
Expand Down
Loading

0 comments on commit b5a172c

Please sign in to comment.