hyperapp-is 0.1.35 → 0.1.37
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.
|
@@ -13,4 +13,4 @@ export { Carousel, effect_InitCarousel } from "./animationView/carousel";
|
|
|
13
13
|
export type { ScrollMargin, MatrixState } from "./dom/utils";
|
|
14
14
|
export { getScrollMargin, getMatrixState } from "./dom/utils";
|
|
15
15
|
export type { GoogleAccountsId, GoogleTokenClient, GoogleAccountsOAuth2, GoogleAccounts, Google, GoogleAuthConfig, GoogleUser, GoogleAuthResult, GoogleScope, GetAccessTokenConfig } from "./services/google";
|
|
16
|
-
export { getGoogle,
|
|
16
|
+
export { getGoogle, getGoogleAuthResult, googleAuth, getAccessToken } from "./services/google";
|
|
@@ -7,4 +7,4 @@ export { progress_easing } from "./animation/easing";
|
|
|
7
7
|
export { createUnits, createRAFProperties, effect_RAFProperties } from "./animation/properties";
|
|
8
8
|
export { Carousel, effect_InitCarousel } from "./animationView/carousel";
|
|
9
9
|
export { getScrollMargin, getMatrixState } from "./dom/utils";
|
|
10
|
-
export { getGoogle,
|
|
10
|
+
export { getGoogle, getGoogleAuthResult, googleAuth, getAccessToken } from "./services/google";
|
|
@@ -10,6 +10,12 @@ export interface GoogleAccountsId {
|
|
|
10
10
|
disableAutoSelect(): void;
|
|
11
11
|
cancel(): void;
|
|
12
12
|
prompt(callback?: (notification: any) => void): void;
|
|
13
|
+
renderButton(parent: HTMLElement, options?: {
|
|
14
|
+
theme?: "outline" | "filled_blue" | "filled_black";
|
|
15
|
+
size?: "large" | "medium" | "small";
|
|
16
|
+
text?: "signin_with" | "signup_with" | "continue_with";
|
|
17
|
+
shape?: "rectangular" | "pill" | "circle" | "square";
|
|
18
|
+
}): void;
|
|
13
19
|
}
|
|
14
20
|
export interface GoogleTokenClient {
|
|
15
21
|
requestAccessToken(options?: {
|
|
@@ -49,8 +55,8 @@ export interface GoogleAuthResult {
|
|
|
49
55
|
idToken: string;
|
|
50
56
|
user: GoogleUser;
|
|
51
57
|
}
|
|
52
|
-
export declare const
|
|
53
|
-
export declare const
|
|
58
|
+
export declare const getGoogleAuthResult: (idToken: string) => GoogleAuthResult;
|
|
59
|
+
export declare const googleAuth: (config: GoogleAuthConfig) => Promise<GoogleAuthResult | null>;
|
|
54
60
|
export type GoogleScope = "openid" | "email" | "profile" | "https://www.googleapis.com/auth/drive" | "https://www.googleapis.com/auth/drive.readonly" | "https://www.googleapis.com/auth/drive.file" | "https://www.googleapis.com/auth/drive.metadata.readonly" | "https://www.googleapis.com/auth/drive.appdata" | "https://www.googleapis.com/auth/calendar" | "https://www.googleapis.com/auth/calendar.readonly" | "https://www.googleapis.com/auth/calendar.events" | "https://www.googleapis.com/auth/calendar.events.readonly" | "https://www.googleapis.com/auth/gmail.readonly" | "https://www.googleapis.com/auth/gmail.modify" | "https://www.googleapis.com/auth/gmail.send" | "https://www.googleapis.com/auth/gmail.compose" | "https://www.googleapis.com/auth/gmail.labels" | "https://www.googleapis.com/auth/spreadsheets" | "https://www.googleapis.com/auth/spreadsheets.readonly" | "https://www.googleapis.com/auth/documents" | "https://www.googleapis.com/auth/documents.readonly" | "https://www.googleapis.com/auth/presentations" | "https://www.googleapis.com/auth/presentations.readonly" | "https://www.googleapis.com/auth/forms" | "https://www.googleapis.com/auth/forms.responses.readonly" | "https://www.googleapis.com/auth/youtube.readonly" | "https://www.googleapis.com/auth/youtube" | "https://www.googleapis.com/auth/youtube.upload" | "https://www.googleapis.com/auth/youtube.force-ssl" | "https://www.googleapis.com/auth/userinfo.email" | "https://www.googleapis.com/auth/userinfo.profile" | (string & {});
|
|
55
61
|
export interface GetAccessTokenConfig {
|
|
56
62
|
clientId: string;
|
|
@@ -35,6 +35,29 @@ export const getGoogle = async () => {
|
|
|
35
35
|
return googlePromise;
|
|
36
36
|
};
|
|
37
37
|
// ---------- ---------- ---------- ---------- ----------
|
|
38
|
+
// getGoogleAuthResult
|
|
39
|
+
// ---------- ---------- ---------- ---------- ----------
|
|
40
|
+
export const getGoogleAuthResult = (idToken) => {
|
|
41
|
+
const base64 = idToken.split(".")[1]
|
|
42
|
+
.replace(/-/g, "+")
|
|
43
|
+
.replace(/_/g, "/");
|
|
44
|
+
const decode = (str) => decodeURIComponent(atob(str)
|
|
45
|
+
.split("")
|
|
46
|
+
.map(c => "%" + ("00" + c.charCodeAt(0).toString(16)).slice(-2))
|
|
47
|
+
.join(""));
|
|
48
|
+
const payload = JSON.parse(decode(base64));
|
|
49
|
+
const user = {
|
|
50
|
+
name: payload.name,
|
|
51
|
+
email: payload.email,
|
|
52
|
+
picture: payload.picture,
|
|
53
|
+
sub: payload.sub
|
|
54
|
+
};
|
|
55
|
+
return {
|
|
56
|
+
idToken,
|
|
57
|
+
user
|
|
58
|
+
};
|
|
59
|
+
};
|
|
60
|
+
// ---------- ---------- ---------- ---------- ----------
|
|
38
61
|
// googleAuth
|
|
39
62
|
// ---------- ---------- ---------- ---------- ----------
|
|
40
63
|
export const googleAuth = async (config) => {
|
|
@@ -56,21 +79,7 @@ export const googleAuth = async (config) => {
|
|
|
56
79
|
callback: (response) => {
|
|
57
80
|
try {
|
|
58
81
|
const idToken = response.credential;
|
|
59
|
-
|
|
60
|
-
.replace(/-/g, "+")
|
|
61
|
-
.replace(/_/g, "/");
|
|
62
|
-
const decode = (str) => decodeURIComponent(atob(str)
|
|
63
|
-
.split("")
|
|
64
|
-
.map(c => "%" + ("00" + c.charCodeAt(0).toString(16)).slice(-2))
|
|
65
|
-
.join(""));
|
|
66
|
-
const payload = JSON.parse(decode(base64));
|
|
67
|
-
const user = {
|
|
68
|
-
name: payload.name,
|
|
69
|
-
email: payload.email,
|
|
70
|
-
picture: payload.picture,
|
|
71
|
-
sub: payload.sub
|
|
72
|
-
};
|
|
73
|
-
resolve({ idToken, user });
|
|
82
|
+
resolve(getGoogleAuthResult(idToken));
|
|
74
83
|
}
|
|
75
84
|
catch (error) {
|
|
76
85
|
reject(error);
|
|
@@ -80,52 +89,39 @@ export const googleAuth = async (config) => {
|
|
|
80
89
|
// show prompt
|
|
81
90
|
client.prompt((notification) => {
|
|
82
91
|
if (notification.isNotDisplayed() || notification.isSkippedMoment()) {
|
|
83
|
-
|
|
92
|
+
resolve(null);
|
|
84
93
|
}
|
|
85
94
|
});
|
|
86
95
|
}); // end result
|
|
87
96
|
};
|
|
88
97
|
// ---------- ---------- ---------- ---------- ----------
|
|
89
|
-
// googleLogout
|
|
90
|
-
// ---------- ---------- ---------- ---------- ----------
|
|
91
|
-
export const googleLogout = async () => {
|
|
92
|
-
const google = await getGoogle();
|
|
93
|
-
// 自動ログインを無効化
|
|
94
|
-
google.accounts.id.disableAutoSelect();
|
|
95
|
-
// セッション的なものをクリア(念のため)
|
|
96
|
-
google.accounts.id.cancel();
|
|
97
|
-
};
|
|
98
|
-
// ---------- ---------- ---------- ---------- ----------
|
|
99
98
|
// getAccessToken
|
|
100
99
|
// ---------- ---------- ---------- ---------- ----------
|
|
101
|
-
export const getAccessToken = (config) =>
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
scope: config.scope.join(" "),
|
|
115
|
-
callback: (response) => {
|
|
116
|
-
if (response.error) {
|
|
117
|
-
reject(response);
|
|
118
|
-
}
|
|
119
|
-
else {
|
|
120
|
-
if (response.access_token) {
|
|
121
|
-
resolve(response.access_token);
|
|
100
|
+
export const getAccessToken = async (config) => {
|
|
101
|
+
const google = await getGoogle();
|
|
102
|
+
return new Promise((resolve, reject) => {
|
|
103
|
+
var _a;
|
|
104
|
+
// variable
|
|
105
|
+
const prompt = (_a = config.prompt) !== null && _a !== void 0 ? _a : "select_account";
|
|
106
|
+
// initialize
|
|
107
|
+
const tokenClient = google.accounts.oauth2.initTokenClient({
|
|
108
|
+
client_id: config.clientId,
|
|
109
|
+
scope: config.scope.join(" "),
|
|
110
|
+
callback: (response) => {
|
|
111
|
+
if (response.error) {
|
|
112
|
+
reject(response);
|
|
122
113
|
}
|
|
123
114
|
else {
|
|
124
|
-
|
|
115
|
+
if (response.access_token) {
|
|
116
|
+
resolve(response.access_token);
|
|
117
|
+
}
|
|
118
|
+
else {
|
|
119
|
+
reject(new Error("No access_token"));
|
|
120
|
+
}
|
|
125
121
|
}
|
|
126
122
|
}
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
}
|
|
123
|
+
}); // end initialize
|
|
124
|
+
// request AccessToken
|
|
125
|
+
tokenClient.requestAccessToken({ prompt }); // prompt == "none" のときには、事前にログインが必要
|
|
126
|
+
});
|
|
127
|
+
};
|