flashauthbyjagwar 1.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/LICENSE +7 -0
- package/README.md +6 -0
- package/dist/APIs/API.d.ts +11 -0
- package/dist/APIs/API.d.ts.map +1 -0
- package/dist/APIs/API.js +94 -0
- package/dist/FlashAuthClient.d.ts +13 -0
- package/dist/FlashAuthClient.d.ts.map +1 -0
- package/dist/FlashAuthClient.js +71 -0
- package/dist/Interfaces/ILocalPopupManager.d.ts +4 -0
- package/dist/Interfaces/ILocalPopupManager.d.ts.map +1 -0
- package/dist/Interfaces/ILocalPopupManager.js +1 -0
- package/dist/Interfaces/IOAuthPopupManager.d.ts +10 -0
- package/dist/Interfaces/IOAuthPopupManager.d.ts.map +1 -0
- package/dist/Interfaces/IOAuthPopupManager.js +1 -0
- package/dist/Interfaces/IOAuthProvider.d.ts +4 -0
- package/dist/Interfaces/IOAuthProvider.d.ts.map +1 -0
- package/dist/Interfaces/IOAuthProvider.js +1 -0
- package/dist/Interfaces/ProviderIN.d.ts +8 -0
- package/dist/Interfaces/ProviderIN.d.ts.map +1 -0
- package/dist/Interfaces/ProviderIN.js +1 -0
- package/dist/Managers/AuthManager.d.ts +9 -0
- package/dist/Managers/AuthManager.d.ts.map +1 -0
- package/dist/Managers/AuthManager.js +37 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +2 -0
- package/dist/providers/GithubAuthProvider.d.ts +4 -0
- package/dist/providers/GithubAuthProvider.d.ts.map +1 -0
- package/dist/providers/GithubAuthProvider.js +6 -0
- package/dist/providers/GoogleAuthProvider.d.ts +4 -0
- package/dist/providers/GoogleAuthProvider.d.ts.map +1 -0
- package/dist/providers/GoogleAuthProvider.js +12 -0
- package/dist/providers/LocalAuthPopupManager.d.ts +5 -0
- package/dist/providers/LocalAuthPopupManager.d.ts.map +1 -0
- package/dist/providers/LocalAuthPopupManager.js +7 -0
- package/dist/providers/OAuthPopupManager.d.ts +6 -0
- package/dist/providers/OAuthPopupManager.d.ts.map +1 -0
- package/dist/providers/OAuthPopupManager.js +32 -0
- package/dist/utils/Storage.d.ts +7 -0
- package/dist/utils/Storage.d.ts.map +1 -0
- package/dist/utils/Storage.js +31 -0
- package/package.json +51 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
Copyright (c) 2025 Jagwar. All rights reserved.
|
|
2
|
+
|
|
3
|
+
This software and associated documentation files (the "Software") are the exclusive property of Jagwar.
|
|
4
|
+
|
|
5
|
+
Unauthorized copying, modification, distribution, or use of this Software, in whole or in part, is strictly prohibited without the express written permission of the copyright holder.
|
|
6
|
+
|
|
7
|
+
For licensing inquiries, please contact: https://github.com/jagwar7
|
package/README.md
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
interface UserData {
|
|
2
|
+
success: boolean;
|
|
3
|
+
message: string;
|
|
4
|
+
data: any;
|
|
5
|
+
}
|
|
6
|
+
export declare function GetGoogleLoginURL(serverURL: string, clientId: string): Promise<string>;
|
|
7
|
+
export declare function SignUpWithJWT(serverURL: string, clientId: string, name: string, email: string, password: string): Promise<string>;
|
|
8
|
+
export declare function SingInWithJWT(serverURL: string, clientId: string, email: string, password: string): Promise<any>;
|
|
9
|
+
export declare function FetchProfile(serverURL: string, clientId: string, token: string): Promise<string | UserData>;
|
|
10
|
+
export {};
|
|
11
|
+
//# sourceMappingURL=API.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"API.d.ts","sourceRoot":"","sources":["../../src/APIs/API.ts"],"names":[],"mappings":"AAEA,UAAU,QAAQ;IAChB,OAAO,EAAE,OAAO,CAAC;IACjB,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,GAAG,CAAC;CACX;AAQD,wBAAsB,iBAAiB,CAAC,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CA4B5F;AAgBD,wBAAsB,aAAa,CAAC,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAoBvI;AAKD,wBAAsB,aAAa,CAAC,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,KAAK,EAAC,MAAM,EAAE,QAAQ,EAAC,MAAM,gBAyBrG;AAWD,wBAAsB,YAAY,CAAC,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,8BAsBpF"}
|
package/dist/APIs/API.js
ADDED
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import axios from "axios";
|
|
2
|
+
export async function GetGoogleLoginURL(serverURL, clientId) {
|
|
3
|
+
if (!clientId || !serverURL) {
|
|
4
|
+
throw new Error("Missing client ID or server url");
|
|
5
|
+
}
|
|
6
|
+
try {
|
|
7
|
+
const url = `${serverURL}/api/flashauth/google/url`;
|
|
8
|
+
const res = await fetch(url, {
|
|
9
|
+
method: 'GET',
|
|
10
|
+
headers: {
|
|
11
|
+
'Content-Type': 'application/json',
|
|
12
|
+
'X-Client-Id': clientId
|
|
13
|
+
}
|
|
14
|
+
});
|
|
15
|
+
if (!res.ok) {
|
|
16
|
+
const errorData = await res.json();
|
|
17
|
+
throw new Error(`Failed to get provider login URL: ${errorData.error || res.statusText}`);
|
|
18
|
+
}
|
|
19
|
+
const data = await res.json();
|
|
20
|
+
if (data.success == false) {
|
|
21
|
+
throw new Error('Failed to get login URL, Contact Admin');
|
|
22
|
+
}
|
|
23
|
+
return data.url;
|
|
24
|
+
}
|
|
25
|
+
catch (err) {
|
|
26
|
+
throw err;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
export async function SignUpWithJWT(serverURL, clientId, name, email, password) {
|
|
30
|
+
if (!serverURL || !clientId || !name || !email || !password) {
|
|
31
|
+
throw new Error("All the fields are required");
|
|
32
|
+
}
|
|
33
|
+
try {
|
|
34
|
+
const payload = {
|
|
35
|
+
name, email, password
|
|
36
|
+
};
|
|
37
|
+
const res = await axios.post(`${serverURL}/api/flashauth/local/signup`, payload, {
|
|
38
|
+
headers: {
|
|
39
|
+
'Content-Type': 'application/json',
|
|
40
|
+
'X-Client-Id': clientId
|
|
41
|
+
}
|
|
42
|
+
});
|
|
43
|
+
return res.data;
|
|
44
|
+
}
|
|
45
|
+
catch (error) {
|
|
46
|
+
throw new Error("There is an error with sign up");
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
export async function SingInWithJWT(serverURL, clientId, email, password) {
|
|
50
|
+
const proivder = 'local';
|
|
51
|
+
if (!serverURL || !clientId || !email || !password) {
|
|
52
|
+
throw new Error("All the fields are required");
|
|
53
|
+
}
|
|
54
|
+
try {
|
|
55
|
+
const payload = {
|
|
56
|
+
email, password, authType: proivder
|
|
57
|
+
};
|
|
58
|
+
const url = `${serverURL}/api/flashauth/local/signin`;
|
|
59
|
+
const signInResponse = await fetch(url, {
|
|
60
|
+
method: 'POST',
|
|
61
|
+
headers: {
|
|
62
|
+
'Content-Type': 'application/json',
|
|
63
|
+
'X-Client-Id': clientId,
|
|
64
|
+
},
|
|
65
|
+
body: JSON.stringify(payload)
|
|
66
|
+
});
|
|
67
|
+
const res = signInResponse.json();
|
|
68
|
+
return res;
|
|
69
|
+
}
|
|
70
|
+
catch (error) {
|
|
71
|
+
throw new Error("There is a problem while signing in");
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
export async function FetchProfile(serverURL, clientId, token) {
|
|
75
|
+
if (!serverURL || !clientId || !token) {
|
|
76
|
+
throw new Error("All the fields are required");
|
|
77
|
+
}
|
|
78
|
+
try {
|
|
79
|
+
const userResponse = await axios.get(`${serverURL}/api/flashauth/fetch/profile`, {
|
|
80
|
+
headers: {
|
|
81
|
+
'Content-Type': 'application/json',
|
|
82
|
+
'X-Client-Id': clientId,
|
|
83
|
+
Authorization: `Bearer:${token}`
|
|
84
|
+
}
|
|
85
|
+
});
|
|
86
|
+
if (userResponse.data.success == false) {
|
|
87
|
+
return userResponse.data.message;
|
|
88
|
+
}
|
|
89
|
+
return userResponse.data;
|
|
90
|
+
}
|
|
91
|
+
catch (error) {
|
|
92
|
+
throw new Error("There is an error with Fetching user profile");
|
|
93
|
+
}
|
|
94
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
declare class FlashAuthClient {
|
|
2
|
+
private clientId;
|
|
3
|
+
private serverURL;
|
|
4
|
+
private authManager;
|
|
5
|
+
constructor(clientId: string);
|
|
6
|
+
SignInWithGoogle(): Promise<string>;
|
|
7
|
+
FetchUserProfile(): Promise<any>;
|
|
8
|
+
SignOut(): Promise<any>;
|
|
9
|
+
FetchUserToken(): any;
|
|
10
|
+
checkTokenExpiry(): void;
|
|
11
|
+
}
|
|
12
|
+
export default FlashAuthClient;
|
|
13
|
+
//# sourceMappingURL=FlashAuthClient.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"FlashAuthClient.d.ts","sourceRoot":"","sources":["../src/FlashAuthClient.ts"],"names":[],"mappings":"AAMA,cAAM,eAAe;IACnB,OAAO,CAAC,QAAQ,CAAU;IAC1B,OAAO,CAAC,SAAS,CAAoD;IACrE,OAAO,CAAC,WAAW,CAAc;gBAIrB,QAAQ,EAAC,MAAM;IAsBrB,gBAAgB,IAAI,OAAO,CAAC,MAAM,CAAC;IAyBnC,gBAAgB,IAAK,OAAO,CAAC,GAAG,CAAC;IAkBjC,OAAO,IAAK,OAAO,CAAC,GAAG,CAAC;IAe9B,cAAc,IAAI,GAAG;IAQrB,gBAAgB;CAcjB;AAGD,eAAe,eAAe,CAAC"}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { FetchProfile } from "./APIs/API";
|
|
2
|
+
import AuthManager from "./Managers/AuthManager";
|
|
3
|
+
import Storage from "./utils/Storage";
|
|
4
|
+
import { jwtDecode } from 'jwt-decode';
|
|
5
|
+
class FlashAuthClient {
|
|
6
|
+
constructor(clientId) {
|
|
7
|
+
this.serverURL = "https://jagwar-flash-auth.onrender.com";
|
|
8
|
+
try {
|
|
9
|
+
if (!clientId) {
|
|
10
|
+
throw new Error("Flash Auth: Client public key is required");
|
|
11
|
+
}
|
|
12
|
+
this.clientId = clientId;
|
|
13
|
+
this.authManager = new AuthManager(this.clientId, this.serverURL);
|
|
14
|
+
this.serverURL = "https://jagwar-flash-auth.onrender.com";
|
|
15
|
+
this.checkTokenExpiry();
|
|
16
|
+
}
|
|
17
|
+
catch (error) {
|
|
18
|
+
console.log("Flash Auth: Initialization error", error);
|
|
19
|
+
throw error;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
async SignInWithGoogle() {
|
|
23
|
+
try {
|
|
24
|
+
return await this.authManager.SignInWithGoogle();
|
|
25
|
+
}
|
|
26
|
+
catch (error) {
|
|
27
|
+
console.log("Flash Auth: Google login error ", error);
|
|
28
|
+
throw error;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
async FetchUserProfile() {
|
|
32
|
+
try {
|
|
33
|
+
const token = Storage.Get();
|
|
34
|
+
if (!token)
|
|
35
|
+
return "Authentication token does not exist. Please sign in.";
|
|
36
|
+
const res = await FetchProfile(this.serverURL, this.clientId, token);
|
|
37
|
+
return res;
|
|
38
|
+
}
|
|
39
|
+
catch (error) {
|
|
40
|
+
throw error;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
async SignOut() {
|
|
44
|
+
try {
|
|
45
|
+
Storage.Remove();
|
|
46
|
+
window.location.reload();
|
|
47
|
+
}
|
|
48
|
+
catch (error) {
|
|
49
|
+
throw error;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
FetchUserToken() {
|
|
53
|
+
return Storage.Get();
|
|
54
|
+
}
|
|
55
|
+
checkTokenExpiry() {
|
|
56
|
+
const token = this.FetchUserToken();
|
|
57
|
+
if (!token)
|
|
58
|
+
return;
|
|
59
|
+
try {
|
|
60
|
+
const decoded = jwtDecode(token);
|
|
61
|
+
const currentTime = Date.now() / 1000;
|
|
62
|
+
if (decoded.exp && decoded.exp < currentTime) {
|
|
63
|
+
Storage.Remove();
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
catch (error) {
|
|
67
|
+
console.error(error);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
export default FlashAuthClient;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ILocalPopupManager.d.ts","sourceRoot":"","sources":["../../src/Interfaces/ILocalPopupManager.ts"],"names":[],"mappings":"AAEA,MAAM,WAAW,kBAAkB;IAC/B,oBAAoB,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,EAAC,MAAM,EAAE,KAAK,EAAC,MAAM,EAAE,MAAM,EAAC,MAAM,GAAI,MAAM,GAAG,IAAI,CAAC;CAC/F"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export interface AuthMessage {
|
|
2
|
+
type: "FLASHAUTH_TOKEN" | "FLASHAUTH_ERROR";
|
|
3
|
+
token?: string;
|
|
4
|
+
error?: string;
|
|
5
|
+
}
|
|
6
|
+
export interface IOAuthPopupManager {
|
|
7
|
+
openPopupURL(url: string, name: string, width: number, height: number): Window | null;
|
|
8
|
+
handleAuthResponse(popup: Window, serverURL: string): Promise<string>;
|
|
9
|
+
}
|
|
10
|
+
//# sourceMappingURL=IOAuthPopupManager.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"IOAuthPopupManager.d.ts","sourceRoot":"","sources":["../../src/Interfaces/IOAuthPopupManager.ts"],"names":[],"mappings":"AAKA,MAAM,WAAW,WAAW;IACxB,IAAI,EAAE,iBAAiB,GAAG,iBAAiB,CAAC;IAC5C,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,KAAK,CAAC,EAAE,MAAM,CAAC;CAClB;AAED,MAAM,WAAW,kBAAkB;IAC/B,YAAY,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,EAAC,MAAM,EAAE,KAAK,EAAC,MAAM,EAAE,MAAM,EAAC,MAAM,GAAI,MAAM,GAAG,IAAI,CAAC;IACpF,kBAAkB,CAAC,KAAK,EAAC,MAAM,EAAE,SAAS,EAAC,MAAM,GAAI,OAAO,CAAC,MAAM,CAAC,CAAC;CACxE"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"IOAuthProvider.d.ts","sourceRoot":"","sources":["../../src/Interfaces/IOAuthProvider.ts"],"names":[],"mappings":"AAAA,UAAU,cAAc;IACpB,WAAW,CAAC,QAAQ,EAAC,MAAM,EAAE,SAAS,EAAC,MAAM,GAAI,OAAO,CAAC,MAAM,CAAC,CAAC;CACpE"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ProviderIN.d.ts","sourceRoot":"","sources":["../../src/Interfaces/ProviderIN.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,QAAQ,GAAG,QAAQ,GAAG,UAAU,GAAG,QAAQ,GAAG,OAAO,GAAG,UAAU,CAAC;AAC/E,MAAM,WAAW,WAAW;IACxB,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;IACd,SAAS,CAAC,EAAE,MAAM,CAAC;CACtB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export default class AuthManager {
|
|
2
|
+
private ClientId;
|
|
3
|
+
private ServerURL;
|
|
4
|
+
private OAuthPopupManager;
|
|
5
|
+
private LocalAuthPopupManager;
|
|
6
|
+
constructor(clientId: string, serverURL: string);
|
|
7
|
+
SignInWithGoogle(): Promise<string>;
|
|
8
|
+
}
|
|
9
|
+
//# sourceMappingURL=AuthManager.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AuthManager.d.ts","sourceRoot":"","sources":["../../src/Managers/AuthManager.ts"],"names":[],"mappings":"AAQA,MAAM,CAAC,OAAO,OAAO,WAAW;IAC5B,OAAO,CAAC,QAAQ,CAAS;IACzB,OAAO,CAAC,SAAS,CAAS;IAC1B,OAAO,CAAC,iBAAiB,CAAsB;IAC/C,OAAO,CAAC,qBAAqB,CAAsB;gBAEvC,QAAQ,EAAE,MAAM,EAAE,SAAS,EAAC,MAAM;IAcxC,gBAAgB,IAAI,OAAO,CAAC,MAAM,CAAC;CAwB5C"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import GoogleAuthProvider from "../providers/GoogleAuthProvider";
|
|
2
|
+
import OAuthPopupManager from "../providers/OAuthPopupManager";
|
|
3
|
+
import Storage from "../utils/Storage";
|
|
4
|
+
import LocalAuthPopupManager from "../providers/LocalAuthPopupManager";
|
|
5
|
+
export default class AuthManager {
|
|
6
|
+
constructor(clientId, serverURL) {
|
|
7
|
+
try {
|
|
8
|
+
if (!clientId)
|
|
9
|
+
throw new Error("Missing client public key");
|
|
10
|
+
this.ClientId = clientId;
|
|
11
|
+
this.ServerURL = serverURL;
|
|
12
|
+
this.OAuthPopupManager = new OAuthPopupManager();
|
|
13
|
+
this.LocalAuthPopupManager = new LocalAuthPopupManager();
|
|
14
|
+
}
|
|
15
|
+
catch (error) {
|
|
16
|
+
console.log("AuthManager intialization error", error);
|
|
17
|
+
throw error;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
async SignInWithGoogle() {
|
|
21
|
+
try {
|
|
22
|
+
const googleProvider = new GoogleAuthProvider();
|
|
23
|
+
const url = await googleProvider.GetLoginURL(this.ClientId, this.ServerURL);
|
|
24
|
+
console.log("O AUTH URL", url);
|
|
25
|
+
const popup = this.OAuthPopupManager.openPopupURL(url, "GoogleAuth", 500, 600);
|
|
26
|
+
if (!popup)
|
|
27
|
+
throw new Error("FlashAuth: Popup blocked by browser");
|
|
28
|
+
const token = await this.OAuthPopupManager.handleAuthResponse(popup, this.ServerURL);
|
|
29
|
+
Storage.Set(token);
|
|
30
|
+
return token;
|
|
31
|
+
}
|
|
32
|
+
catch (error) {
|
|
33
|
+
console.log("AuthManager: Google login error");
|
|
34
|
+
throw error;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,eAAe,MAAM,mBAAmB,CAAC;AAEhD,eAAe,eAAe,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"GithubAuthProvider.d.ts","sourceRoot":"","sources":["../../src/providers/GithubAuthProvider.ts"],"names":[],"mappings":"AAEA,cAAM,kBAAmB,YAAW,cAAc;IACxC,WAAW,CAAC,QAAQ,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;CAG1E"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"GoogleAuthProvider.d.ts","sourceRoot":"","sources":["../../src/providers/GoogleAuthProvider.ts"],"names":[],"mappings":"AAGA,MAAM,CAAC,OAAO,OAAO,kBAAmB,YAAW,cAAc;IACvD,WAAW,CAAC,QAAQ,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;CAQ1E"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { GetGoogleLoginURL } from "../APIs/API";
|
|
2
|
+
export default class GoogleAuthProvider {
|
|
3
|
+
async GetLoginURL(CliendId, serverURL) {
|
|
4
|
+
try {
|
|
5
|
+
return await GetGoogleLoginURL(serverURL, CliendId);
|
|
6
|
+
}
|
|
7
|
+
catch (error) {
|
|
8
|
+
console.log("failed to get google login url", error);
|
|
9
|
+
throw error;
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { ILocalPopupManager } from "../Interfaces/ILocalPopupManager";
|
|
2
|
+
export default class LocalAuthPopupManager implements ILocalPopupManager {
|
|
3
|
+
openLocalPopupWindow(page: string, name: string, width: number, height: number): Window | null;
|
|
4
|
+
}
|
|
5
|
+
//# sourceMappingURL=LocalAuthPopupManager.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"LocalAuthPopupManager.d.ts","sourceRoot":"","sources":["../../src/providers/LocalAuthPopupManager.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,kCAAkC,CAAC;AAItE,MAAM,CAAC,OAAO,OAAO,qBAAsB,YAAW,kBAAkB;IACpE,oBAAoB,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI;CAKjG"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export default class LocalAuthPopupManager {
|
|
2
|
+
openLocalPopupWindow(page, name, width, height) {
|
|
3
|
+
const left = window.screenX + (window.outerWidth - width) / 2;
|
|
4
|
+
const top = window.screenY + (window.outerHeight - height) / 2;
|
|
5
|
+
return window.open(page, name, `width=${width},height=${height},left=${left},top=${top}`);
|
|
6
|
+
}
|
|
7
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { IOAuthPopupManager } from "../Interfaces/IOAuthPopupManager";
|
|
2
|
+
export default class OAuthPopupManager implements IOAuthPopupManager {
|
|
3
|
+
openPopupURL(url: string, name: "Flash Auth", width: 500, height: 600): Window | null;
|
|
4
|
+
handleAuthResponse(popup: Window, serverURL: string): Promise<string>;
|
|
5
|
+
}
|
|
6
|
+
//# sourceMappingURL=OAuthPopupManager.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"OAuthPopupManager.d.ts","sourceRoot":"","sources":["../../src/providers/OAuthPopupManager.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAI,MAAM,kCAAkC,CAAC;AAExE,MAAM,CAAC,OAAO,OAAO,iBAAkB,YAAW,kBAAkB;IAEhE,YAAY,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,YAAY,EAAE,KAAK,EAAE,GAAG,EAAE,MAAM,EAAE,GAAG,GAAG,MAAM,GAAG,IAAI;IAM/E,kBAAkB,CAAC,KAAK,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;CA+B9E"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
export default class OAuthPopupManager {
|
|
2
|
+
openPopupURL(url, name, width, height) {
|
|
3
|
+
const left = window.screenX + (window.outerWidth - width) / 2;
|
|
4
|
+
const top = window.screenY + (window.outerHeight - height) / 2;
|
|
5
|
+
return window.open(url, name, `width=${width},height=${height},left=${left},top=${top}`);
|
|
6
|
+
}
|
|
7
|
+
async handleAuthResponse(popup, serverURL) {
|
|
8
|
+
return await new Promise((resolve, reject) => {
|
|
9
|
+
const popupEventResponse = (event) => {
|
|
10
|
+
if (event.origin !== serverURL.replace(/\/$/, ""))
|
|
11
|
+
return;
|
|
12
|
+
const data = event.data;
|
|
13
|
+
if (data.type === "FLASHAUTH_TOKEN" && data.token) {
|
|
14
|
+
window.removeEventListener("message", popupEventResponse);
|
|
15
|
+
resolve(data.token);
|
|
16
|
+
}
|
|
17
|
+
else if (data.type === "FLASHAUTH_ERROR") {
|
|
18
|
+
window.removeEventListener("message", popupEventResponse);
|
|
19
|
+
reject(new Error(data.error || "Authentication Failed"));
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
window.addEventListener("message", popupEventResponse);
|
|
23
|
+
const checkPopup = setInterval(() => {
|
|
24
|
+
if (popup.closed) {
|
|
25
|
+
clearInterval(checkPopup);
|
|
26
|
+
window.removeEventListener("message", popupEventResponse);
|
|
27
|
+
reject(new Error("FlashAuth: Popup closed by user"));
|
|
28
|
+
}
|
|
29
|
+
}, 500);
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Storage.d.ts","sourceRoot":"","sources":["../../src/utils/Storage.ts"],"names":[],"mappings":"AACA,QAAA,MAAM,OAAO;eACE,MAAM;WAWV,MAAM,GAAG,IAAI;;CAqBvB,CAAC;AACF,eAAe,OAAO,CAAC"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
const Storage = {
|
|
2
|
+
Set(token) {
|
|
3
|
+
try {
|
|
4
|
+
const providerKey = `FLASHAUTH_TOKEN`;
|
|
5
|
+
localStorage.setItem(providerKey, token);
|
|
6
|
+
}
|
|
7
|
+
catch (err) {
|
|
8
|
+
console.error("FlashAuth Storage Error:", err);
|
|
9
|
+
}
|
|
10
|
+
},
|
|
11
|
+
Get() {
|
|
12
|
+
try {
|
|
13
|
+
const providerKey = `FLASHAUTH_TOKEN`;
|
|
14
|
+
return localStorage.getItem(providerKey);
|
|
15
|
+
}
|
|
16
|
+
catch (err) {
|
|
17
|
+
console.error("FlashAuth Storage Error:", err);
|
|
18
|
+
return null;
|
|
19
|
+
}
|
|
20
|
+
},
|
|
21
|
+
Remove() {
|
|
22
|
+
try {
|
|
23
|
+
const providerKey = `FLASHAUTH_TOKEN`;
|
|
24
|
+
localStorage.removeItem(providerKey);
|
|
25
|
+
}
|
|
26
|
+
catch (err) {
|
|
27
|
+
console.error("FlashAuth Storage Error:", err);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
export default Storage;
|
package/package.json
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "flashauthbyjagwar",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "An authentication SDK for your React site. No need to write auth logic — just create an account at flashauth.connectjagwar.com to get started.",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"types": "dist/index.d.ts",
|
|
7
|
+
"module": "dist/index.js",
|
|
8
|
+
"files": [
|
|
9
|
+
"dist",
|
|
10
|
+
"README.md",
|
|
11
|
+
"LICENSE"
|
|
12
|
+
],
|
|
13
|
+
"scripts": {
|
|
14
|
+
"build": "tsc",
|
|
15
|
+
"watch": "tsc --watch",
|
|
16
|
+
"clean": "rimraf dist",
|
|
17
|
+
"prepublishOnly": "npm run build"
|
|
18
|
+
},
|
|
19
|
+
"repository": {
|
|
20
|
+
"type": "git",
|
|
21
|
+
"url": "https://github.com/jagwar7/flashauth-sdk.git"
|
|
22
|
+
},
|
|
23
|
+
"keywords": [
|
|
24
|
+
"flashauth",
|
|
25
|
+
"authentication",
|
|
26
|
+
"sdk",
|
|
27
|
+
"firebase",
|
|
28
|
+
"google-signin",
|
|
29
|
+
"typescript",
|
|
30
|
+
"javascript"
|
|
31
|
+
],
|
|
32
|
+
"author": {
|
|
33
|
+
"name": "Jagwar",
|
|
34
|
+
"url": "https://github.com/jagwar7"
|
|
35
|
+
},
|
|
36
|
+
"license": "MIT",
|
|
37
|
+
"bugs": {
|
|
38
|
+
"url": "https://github.com/jagwar7/flashauth-sdk/issues"
|
|
39
|
+
},
|
|
40
|
+
"homepage": "https://github.com/jagwar7/flashauth-sdk#readme",
|
|
41
|
+
"dependencies": {
|
|
42
|
+
"axios": "^1.12.2",
|
|
43
|
+
"firebase": "^12.1.0",
|
|
44
|
+
"jwt-decode": "^4.0.0"
|
|
45
|
+
},
|
|
46
|
+
"devDependencies": {
|
|
47
|
+
"rimraf": "^6.0.1",
|
|
48
|
+
"typescript": "^5.9.2"
|
|
49
|
+
},
|
|
50
|
+
"private": false
|
|
51
|
+
}
|