Skip to content

Commit b3f2f6f

Browse files
committed
fix(google-signin): api changes
1 parent 7ce4846 commit b3f2f6f

File tree

5 files changed

+330
-9384
lines changed

5 files changed

+330
-9384
lines changed

packages/google-signin/index.android.ts

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// @ts-nocheck
12
import { AndroidApplication, Application, AndroidActivityResultEventData, Utils } from '@nativescript/core';
23
import { colorSchemeProperty, ColorSchemeType, colorStyleProperty, ColorStyleType, Configuration, GoogleSignInButtonBase, IUser } from './common';
34
import lazy from '@nativescript/core/utils/lazy';
@@ -13,7 +14,6 @@ const COLOR_DARK = lazy(() => com.google.android.gms.common.SignInButton.COLOR_D
1314
const COLOR_LIGHT = lazy(() => com.google.android.gms.common.SignInButton.COLOR_LIGHT);
1415
const COLOR_AUTO = lazy(() => com.google.android.gms.common.SignInButton.COLOR_AUTO);
1516

16-
1717
export class GoogleError extends Error {
1818
#native: java.lang.Exception;
1919
static fromNative(native: java.lang.Exception, message?: string) {
@@ -27,13 +27,12 @@ export class GoogleError extends Error {
2727
}
2828
}
2929

30-
3130
export class User implements IUser {
32-
#native: com.google.android.gms.auth.api.signin.GoogleSignInAccount;
31+
#native: com.google.android.gms.auth.api.identity.SignInCredential;
3332
#grantedScopes: string[];
3433
#accessToken: string;
35-
static fromNative(account: com.google.android.gms.auth.api.signin.GoogleSignInAccount, accessToken: string = null) {
36-
if (account instanceof com.google.android.gms.auth.api.signin.GoogleSignInAccount) {
34+
static fromNative(account: com.google.android.gms.auth.api.identity.SignInCredential, accessToken: string = null) {
35+
if (account instanceof com.google.android.gms.auth.api.identity.SignInCredential) {
3736
const user = new User();
3837
user.#native = account;
3938
user.#accessToken = accessToken;
@@ -51,7 +50,8 @@ export class User implements IUser {
5150
}
5251

5352
get email() {
54-
return this.native.getEmail();
53+
console.log('request scope for access.');
54+
return '';
5555
}
5656

5757
get givenName() {
@@ -63,7 +63,7 @@ export class User implements IUser {
6363
}
6464

6565
get idToken() {
66-
return this.native.getIdToken();
66+
return this.native.getGoogleIdToken();
6767
}
6868

6969
get accessToken() {
@@ -72,16 +72,17 @@ export class User implements IUser {
7272

7373
get grantedScopes() {
7474
if (!this.#grantedScopes) {
75-
const grantedScopes = [];
76-
const scopes = this.native.getGrantedScopes().toArray();
77-
const length = scopes.length;
78-
for (let i = 0; i < length; i++) {
79-
const scope = scopes[i]?.toString?.();
80-
if (scope) {
81-
grantedScopes.push(scope);
82-
}
83-
}
84-
this.#grantedScopes = grantedScopes;
75+
// removed.
76+
// const grantedScopes = [];
77+
// const scopes = this.native.getGrantedScopes().toArray();
78+
// const length = scopes.length;
79+
// for (let i = 0; i < length; i++) {
80+
// const scope = scopes[i]?.toString?.();
81+
// if (scope) {
82+
// grantedScopes.push(scope);
83+
// }
84+
// }
85+
// this.#grantedScopes = grantedScopes;
8586
}
8687
return this.#grantedScopes;
8788
}
@@ -91,7 +92,7 @@ export class User implements IUser {
9192
}
9293

9394
get serverAuthCode() {
94-
return this.native.getServerAuthCode();
95+
// return this.native.getServerAuthCode();
9596
}
9697

9798
requestScopes(scopes: string[]): Promise<User> {
@@ -248,7 +249,7 @@ export class GoogleSignin {
248249
static playServicesAvailable() {
249250
return new Promise((resolve, reject) => {
250251
resolve(org.nativescript.plugins.googlesignin.GoogleSignIn.playServicesAvailable(false, Application.android.foregroundActivity || Application.android.startActivity));
251-
})
252+
});
252253
}
253254
}
254255

packages/google-signin/index.ios.ts

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ export class GoogleError extends Error {
1717
export class User implements IUser {
1818
#native: GIDGoogleUser;
1919
#grantedScopes: string[];
20+
private _serverAuthCode: string;
2021
static fromNative(user: GIDGoogleUser) {
2122
if (user instanceof GIDGoogleUser) {
2223
const usr = new User();
@@ -47,11 +48,11 @@ export class User implements IUser {
4748
}
4849

4950
get idToken() {
50-
return this.native?.authentication?.idToken;
51+
return this.native?.idToken.tokenString;
5152
}
5253

5354
get accessToken() {
54-
return this.native?.authentication?.accessToken;
55+
return this.native?.accessToken.tokenString;
5556
}
5657

5758
get grantedScopes() {
@@ -75,16 +76,17 @@ export class User implements IUser {
7576
}
7677

7778
get serverAuthCode() {
78-
return this.native.serverAuthCode;
79+
return this._serverAuthCode;
7980
}
8081

8182
requestScopes(scopes: string[]): Promise<User> {
8283
return new Promise((resolve, reject) => {
83-
GIDSignIn.sharedInstance.addScopesPresentingViewControllerCallback(scopes, GoogleSignin.topViewController, (user, error) => {
84+
GIDSignIn.sharedInstance.signInWithPresentingViewControllerHintAdditionalScopesCompletion(GoogleSignin.topViewController, 'Requesting additional scopes', scopes, (result, error) => {
8485
if (error) {
8586
reject(GoogleError.fromNative(error));
8687
} else {
87-
resolve(User.fromNative(user));
88+
this._serverAuthCode = result.serverAuthCode;
89+
resolve(User.fromNative(result.user));
8890
}
8991
});
9092
});
@@ -150,7 +152,7 @@ export class GoogleSignin {
150152

151153
static disconnect(): Promise<void> {
152154
return new Promise((resolve, reject) => {
153-
GIDSignIn.sharedInstance.disconnectWithCallback((error) => {
155+
GIDSignIn.sharedInstance.disconnectWithCompletion((error) => {
154156
if (error) {
155157
reject(GoogleError.fromNative(error));
156158
} else {
@@ -162,19 +164,19 @@ export class GoogleSignin {
162164

163165
static signIn() {
164166
return new Promise((resolve, reject) => {
165-
GIDSignIn.sharedInstance.signInWithConfigurationPresentingViewControllerCallback(this.#nativeConfig, this.topViewController, (user, error) => {
167+
GIDSignIn.sharedInstance.signInWithPresentingViewControllerCompletion(this.topViewController, (result, error) => {
166168
if (error) {
167169
reject(GoogleError.fromNative(error));
168170
} else {
169-
resolve(User.fromNative(user));
171+
resolve(User.fromNative(result?.user));
170172
}
171173
});
172174
});
173175
}
174176

175177
static signInSilently(): Promise<User> {
176178
return new Promise((resolve, reject) => {
177-
GIDSignIn.sharedInstance.restorePreviousSignInWithCallback((user, error) => {
179+
GIDSignIn.sharedInstance.restorePreviousSignInWithCompletion((user, error) => {
178180
if (error) {
179181
reject(GoogleError.fromNative(error));
180182
} else {
@@ -199,7 +201,7 @@ export class GoogleSignin {
199201
return;
200202
}
201203

202-
user.authentication.doWithFreshTokens((auth, error) => {
204+
user.refreshTokensIfNeededWithCompletion((auth, error) => {
203205
if (error) {
204206
reject(GoogleError.fromNative(error));
205207
} else {

packages/google-signin/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@nativescript/google-signin",
3-
"version": "2.0.0",
3+
"version": "2.0.2",
44
"description": "Google Sign-in for your NativeScript applications",
55
"main": "index",
66
"typings": "index.d.ts",

0 commit comments

Comments
 (0)