@leancodepl/login-manager 8.5.1 → 9.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/index.cjs.js CHANGED
@@ -29,6 +29,9 @@ class BaseLoginManager {
29
29
  trySignInWithLinkedIn(accessToken) {
30
30
  return this.acquireToken(this.buildSignInWithLinkedInRequest(accessToken));
31
31
  }
32
+ trySignInWithApple(accessToken) {
33
+ return this.acquireToken(this.buildSignInWithAppleRequest(accessToken));
34
+ }
32
35
  async tryRefreshToken() {
33
36
  const token = await this.storage.getToken();
34
37
  if (token !== null) {
@@ -102,18 +105,6 @@ class BaseLoginManager {
102
105
  body: new URLSearchParams(data)
103
106
  };
104
107
  }
105
- buildSignInWithFacebookRequest(accessToken) {
106
- const data = _extends({
107
- grant_type: "facebook",
108
- scope: this.scopes,
109
- assertion: accessToken
110
- }, this.additionalParams);
111
- return {
112
- method: "POST",
113
- headers: this.prepareHeaders(),
114
- body: new URLSearchParams(data)
115
- };
116
- }
117
108
  buildSignInWithOneTimeTokenRequest(token) {
118
109
  const data = _extends({
119
110
  grant_type: "onetime",
@@ -126,9 +117,9 @@ class BaseLoginManager {
126
117
  body: new URLSearchParams(data)
127
118
  };
128
119
  }
129
- buildSignInWithGoogleRequest(accessToken) {
120
+ buildAssertionSignInRequest(accessToken, grantType) {
130
121
  const data = _extends({
131
- grant_type: "google",
122
+ grant_type: grantType,
132
123
  scope: this.scopes,
133
124
  assertion: accessToken
134
125
  }, this.additionalParams);
@@ -138,17 +129,17 @@ class BaseLoginManager {
138
129
  body: new URLSearchParams(data)
139
130
  };
140
131
  }
132
+ buildSignInWithFacebookRequest(accessToken) {
133
+ return this.buildAssertionSignInRequest(accessToken, "facebook");
134
+ }
135
+ buildSignInWithGoogleRequest(accessToken) {
136
+ return this.buildAssertionSignInRequest(accessToken, "google");
137
+ }
141
138
  buildSignInWithLinkedInRequest(accessToken) {
142
- const data = _extends({
143
- grant_type: "linkedin",
144
- scope: this.scopes,
145
- assertion: accessToken
146
- }, this.additionalParams);
147
- return {
148
- method: "POST",
149
- headers: this.prepareHeaders(),
150
- body: new URLSearchParams(data)
151
- };
139
+ return this.buildAssertionSignInRequest(accessToken, "linkedin");
140
+ }
141
+ buildSignInWithAppleRequest(accessToken) {
142
+ return this.buildAssertionSignInRequest(accessToken, "apple");
152
143
  }
153
144
  buildRefreshRequest(token) {
154
145
  const data = _extends({
package/index.esm.js CHANGED
@@ -27,6 +27,9 @@ class BaseLoginManager {
27
27
  trySignInWithLinkedIn(accessToken) {
28
28
  return this.acquireToken(this.buildSignInWithLinkedInRequest(accessToken));
29
29
  }
30
+ trySignInWithApple(accessToken) {
31
+ return this.acquireToken(this.buildSignInWithAppleRequest(accessToken));
32
+ }
30
33
  async tryRefreshToken() {
31
34
  const token = await this.storage.getToken();
32
35
  if (token !== null) {
@@ -100,18 +103,6 @@ class BaseLoginManager {
100
103
  body: new URLSearchParams(data)
101
104
  };
102
105
  }
103
- buildSignInWithFacebookRequest(accessToken) {
104
- const data = _extends({
105
- grant_type: "facebook",
106
- scope: this.scopes,
107
- assertion: accessToken
108
- }, this.additionalParams);
109
- return {
110
- method: "POST",
111
- headers: this.prepareHeaders(),
112
- body: new URLSearchParams(data)
113
- };
114
- }
115
106
  buildSignInWithOneTimeTokenRequest(token) {
116
107
  const data = _extends({
117
108
  grant_type: "onetime",
@@ -124,9 +115,9 @@ class BaseLoginManager {
124
115
  body: new URLSearchParams(data)
125
116
  };
126
117
  }
127
- buildSignInWithGoogleRequest(accessToken) {
118
+ buildAssertionSignInRequest(accessToken, grantType) {
128
119
  const data = _extends({
129
- grant_type: "google",
120
+ grant_type: grantType,
130
121
  scope: this.scopes,
131
122
  assertion: accessToken
132
123
  }, this.additionalParams);
@@ -136,17 +127,17 @@ class BaseLoginManager {
136
127
  body: new URLSearchParams(data)
137
128
  };
138
129
  }
130
+ buildSignInWithFacebookRequest(accessToken) {
131
+ return this.buildAssertionSignInRequest(accessToken, "facebook");
132
+ }
133
+ buildSignInWithGoogleRequest(accessToken) {
134
+ return this.buildAssertionSignInRequest(accessToken, "google");
135
+ }
139
136
  buildSignInWithLinkedInRequest(accessToken) {
140
- const data = _extends({
141
- grant_type: "linkedin",
142
- scope: this.scopes,
143
- assertion: accessToken
144
- }, this.additionalParams);
145
- return {
146
- method: "POST",
147
- headers: this.prepareHeaders(),
148
- body: new URLSearchParams(data)
149
- };
137
+ return this.buildAssertionSignInRequest(accessToken, "linkedin");
138
+ }
139
+ buildSignInWithAppleRequest(accessToken) {
140
+ return this.buildAssertionSignInRequest(accessToken, "apple");
150
141
  }
151
142
  buildRefreshRequest(token) {
152
143
  const data = _extends({
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@leancodepl/login-manager",
3
- "version": "8.5.1",
3
+ "version": "9.0.0",
4
4
  "license": "Apache-2.0",
5
5
  "dependencies": {
6
6
  "buffer": ">=6.0.0"
@@ -16,8 +16,8 @@ export declare abstract class BaseLoginManager<TStorage extends TokenStorage> {
16
16
  private endpoint;
17
17
  private clientSecret;
18
18
  private clientId;
19
- private scopes;
20
- private additionalParams?;
19
+ protected scopes: string;
20
+ protected additionalParams?: Record<string, string> | undefined;
21
21
  private callbacks;
22
22
  private refreshTokenCallbacks;
23
23
  private isRefreshingToken;
@@ -30,17 +30,20 @@ export declare abstract class BaseLoginManager<TStorage extends TokenStorage> {
30
30
  trySignInWithOneTimeToken(token: string): Promise<LoginResult>;
31
31
  trySignInWithGoogle(accessToken: string): Promise<LoginResult>;
32
32
  trySignInWithLinkedIn(accessToken: string): Promise<LoginResult>;
33
+ trySignInWithApple(accessToken: string): Promise<LoginResult>;
33
34
  tryRefreshToken(): Promise<boolean | null>;
34
35
  protected tryRefreshTokenInternal(token: Token): Promise<boolean>;
35
36
  onChange(callback: (isSignedIn: boolean) => void): void;
36
37
  removeOnChange(callback: (isSignedIn: boolean) => void): void;
37
38
  acquireToken(init: RequestInit): Promise<LoginResult>;
38
39
  buildSignInRequest(username: string, password: string): RequestInit;
39
- private buildSignInWithFacebookRequest;
40
40
  private buildSignInWithOneTimeTokenRequest;
41
+ buildAssertionSignInRequest(accessToken: string, grantType: string): RequestInit;
42
+ private buildSignInWithFacebookRequest;
41
43
  private buildSignInWithGoogleRequest;
42
44
  private buildSignInWithLinkedInRequest;
45
+ private buildSignInWithAppleRequest;
43
46
  private buildRefreshRequest;
44
- private prepareHeaders;
47
+ protected prepareHeaders(): Headers;
45
48
  protected notify(isSignedIn: boolean): void;
46
49
  }