8000 feat(facebook): add authenticationToken to LoginResult (#624) · NativeScript/plugins@e47c189 · GitHub
[go: up one dir, main page]

Skip to content

Commit e47c189

Browse files
feat(facebook): add authenticationToken to LoginResult (#624)
1 parent 4daf33d commit e47c189

File tree

4 files changed

+139
-8
lines changed

4 files changed

+139
-8
lines changed

packages/facebook/common.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,14 @@ export interface IAccessToken {
2626
readonly userID: string;
2727
}
2828

29+
export interface IAuthenticationToken {
30+
readonly graphDomain: string;
31+
32+
readonly nonce: string;
33+
34+
readonly tokenString: string;
35+
}
36+
2937
export interface ILoginResult {
3038
readonly declinedPermissions: string[];
3139

@@ -34,4 +42,6 @@ export interface ILoginResult {
3442
readonly isCancelled: boolean;
3543

3644
readonly token: IAccessToken;
45+
46+
readonly authenticationToken: IAuthenticationToken;
3747
}

packages/facebook/index.android.ts

Lines changed: 53 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -145,16 +145,57 @@ export class AccessToken {
145145
}
146146
}
147147

148+
export class AuthenticationToken {
149+
#native: com.facebook.AuthenticationToken;
150+
151+
static fromNative(authenticationToken: com.facebook.AuthenticationToken) {
152+
if (authenticationToken instanceof com.facebook.AuthenticationToken) {
153+
const token = new AuthenticationToken();
154+
token.#native = authenticationToken;
155+
return token;
156+
}
157+
return null;
158+
}
159+
160+
get nonce(): string {
161+
return this.native.getExpectedNonce();
162+
}
163+
164+
get tokenString(): string {
165+
return this.native.getToken();
166+
}
167+
168+
static currentAuthenticationToken(): AuthenticationToken {
169+
return AuthenticationToken.fromNative(com.facebook.AuthenticationToken.getCurrentAuthenticationToken());
170+
}
171+
172+
toJSON() {
173+
return {
174+
nonce: this.nonce,
175+
tokenString: this.tokenString,
176+
};
177+
}
178+
179+
get native() {
180+
return this.#native;
181+
}
182+
183+
get android() {
184+
return this.native;
185+
}
186+
}
187+
148188
export class LoginResult {
149189
#native: com.facebook.login.LoginResult;
150190
#token: AccessToken;
191+
#authenticationToken: AuthenticationToken;
151192
#declinedPermissions: string[];
152193
#grantedPermissions: string[];
153194
#isCancelled = false;
154-
static fromNative(logingResult: com.facebook.login.LoginResult) {
155-
if (logingResult instanceof com.facebook.login.LoginResult) {
195+
static fromNative(loginResult: com.facebook.login.LoginResult) {
196+
if (loginResult instanceof com.facebook.login.LoginResult) {
156197
const result = new LoginResult();
157-
result.#native = logingResult;
198+
result.#native = loginResult;
158199
return result;
159200
}
160201
return null;
@@ -200,12 +241,20 @@ export class LoginResult {
200241
return this.#token;
201242
}
202243

244+
get authenticationToken(): AuthenticationToken {
245+
if (!this.#authenticationToken) {
246+
this.#authenticationToken = AuthenticationToken.fromNative(this.native.getAuthenticationToken());
247+
}
248+
return this.#authenticationToken;
249+
}
250+
203251
toJSON() {
204252
return {
205253
declinedPermissions: this.declinedPermissions,
206254
grantedPermissions: this.grantedPermissions,
207255
isCancelled: this.isCancelled,
208256
token: this.token,
257+
authenticationToken: this.authenticationToken,
209258
};
210259
}
211260

@@ -252,7 +301,7 @@ export class LoginManager implements ILoginManager {
252301
onError(param0: com.facebook.FacebookException) {
253302
reject(FacebookError.fromNative(param0 as any));
254303
},
255-
})
304+
}),
256305
);
257306
this.#native.logIn(<android.app.Activity>context || Application.android.foregroundActivity || Application.android.startActivity, java.util.Arrays.asList(permissions));
258307
});

packages/facebook/index.d.ts

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { IAccessToken, ILoginResult } from './common';
1+
import { IAccessToken, IAuthenticationToken, ILoginResult } from './common';
22
export declare class FacebookError extends Error {
33
readonly native: any;
44
}
@@ -39,6 +39,22 @@ export declare class AccessToken implements IAccessToken {
3939
readonly ios;
4040
}
4141

42+
export declare class AuthenticationToken implements IAuthenticationToken {
43+
readonly graphDomain: string;
44+
45+
readonly tokenString: string;
46+
47+
readonly nonce: string;
48+
49+
static currentAuthenticationToken(): AuthenticationToken;
50+
51+
readonly native;
52+
53+
readonly android;
54+
55+
readonly ios;
56+
}
57+
4258
export declare class LoginResult implements ILoginResult {
4359
readonly declinedPermissions: string[];
4460

@@ -48,6 +64,8 @@ export declare class LoginResult implements ILoginResult {
4864

4965
readonly token: AccessToken;
5066

67+
readonly authenticationToken: AuthenticationToken;
68+
5169
readonly native;
5270

5371
readonly android;

packages/facebook/index.ios.ts

Lines changed: 57 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -128,16 +128,62 @@ export class AccessToken {
128128
}
129129
}
130130

131+
export class AuthenticationToken {
132+
#native: FBSDKAuthenticationToken;
133+
134+
static fromNative(authenticationToken: FBSDKAuthenticationToken) {
135+
if (authenticationToken instanceof FBSDKAuthenticationToken) {
136+
const token = new AuthenticationToken();
137+
token.#native = authenticationToken;
138+
return token;
139+
}
140+
return null;
141+
}
142+
143+
get graphDomain(): string {
144+
return FBSDKAuthenticationToken.tokenCache?.authenticationToken?.graphDomain;
145+
}
146+
147+
get nonce(): string {
148+
return this.native.nonce;
149+
}
150+
151+
get tokenString(): string {
152+
return this.native.tokenString;
153+
}
154+
155+
static currentAuthenticationToken(): AuthenticationToken {
156+
return AuthenticationToken.fromNative(FBSDKAuthenticationToken.currentAuthenticationToken);
157+
}
158+
159+
toJSON() {
160+
return {
161+
graphDomain: this.graphDomain,
162+
nonce: this.nonce,
163+
tokenString: this.tokenString,
164+
};
165+
}
166+
167+
get native() {
168+
return this.#native;
169+
}
170+
171+
get ios() {
172+
return this.native;
173+
}
174+
}
175+
131176
export class LoginResult {
132177
#native: FBSDKLoginManagerLoginResult;
133178
#token: AccessToken;
179+
#authenticationToken: AuthenticationToken;
134180
#declinedPermissions: string[];
135181
#grantedPermissions: string[];
136182

137-
static fromNative(logingResult: FBSDKLoginManagerLoginResult) {
138-
if (logingResult instanceof FBSDKLoginManagerLoginResult) {
183+
static fromNative(loginResult: FBSDKLoginManagerLoginResult) {
184+
if (loginResult instanceof FBSDKLoginManagerLoginResult) {
139185
const result = new LoginResult();
140-
result.#native = logingResult;
186+
result.#native = loginResult;
141187
return result;
142188
}
143189
return null;
@@ -168,12 +214,20 @@ export class LoginResult {
168214
return this.#token;
169215
}
170216

217+
get authenticationToken(): AuthenticationToken {
218+
if (!this.#authenticationToken) {
219+
this.#authenticationToken = AuthenticationToken.fromNative(this.native.authenticationToken);
220+
}
221+
return this.#authenticationToken;
222+
}
223+
171224
toJSON() {
172225
return {
173226
declinedPermissions: this.declinedPermissions,
174227
grantedPermissions: this.grantedPermissions,
175228
isCancelled: this.isCancelled,
176229
token: this.token,
230+
authenticationToken: this.authenticationToken,
177231
};
178232
}
179233

0 commit comments

Comments
 (0)
0