hyperapp-is 0.1.36 → 0.1.38
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, getAccessToken, effect_googleAuth, googleLogout } 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, getAccessToken, effect_googleAuth, googleLogout } from "./services/google";
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import type { Dispatch, Effect } from "hyperapp";
|
|
2
|
+
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 & {});
|
|
1
3
|
export interface GoogleAccountsId {
|
|
2
4
|
initialize(config: {
|
|
3
5
|
client_id: string;
|
|
@@ -16,6 +18,8 @@ export interface GoogleAccountsId {
|
|
|
16
18
|
text?: "signin_with" | "signup_with" | "continue_with";
|
|
17
19
|
shape?: "rectangular" | "pill" | "circle" | "square";
|
|
18
20
|
}): void;
|
|
21
|
+
revoke(hint: string, // email or sub
|
|
22
|
+
callback: () => void): void;
|
|
19
23
|
}
|
|
20
24
|
export interface GoogleTokenClient {
|
|
21
25
|
requestAccessToken(options?: {
|
|
@@ -39,7 +43,6 @@ export interface GoogleAccounts {
|
|
|
39
43
|
export interface Google {
|
|
40
44
|
accounts: GoogleAccounts;
|
|
41
45
|
}
|
|
42
|
-
export declare const getGoogle: () => Promise<Google>;
|
|
43
46
|
export interface GoogleAuthConfig {
|
|
44
47
|
clientId: string;
|
|
45
48
|
autoSelect?: boolean;
|
|
@@ -55,11 +58,33 @@ export interface GoogleAuthResult {
|
|
|
55
58
|
idToken: string;
|
|
56
59
|
user: GoogleUser;
|
|
57
60
|
}
|
|
58
|
-
export declare const googleAuth: (config: GoogleAuthConfig) => Promise<GoogleAuthResult | null>;
|
|
59
|
-
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 & {});
|
|
60
61
|
export interface GetAccessTokenConfig {
|
|
61
62
|
clientId: string;
|
|
62
63
|
scope: GoogleScope[];
|
|
63
64
|
prompt?: "none" | "select_account" | "consent";
|
|
64
65
|
}
|
|
66
|
+
/**
|
|
67
|
+
* Google 変数を取得する
|
|
68
|
+
*/
|
|
69
|
+
export declare const getGoogle: () => Promise<Google>;
|
|
70
|
+
/**
|
|
71
|
+
* idToken から ユーザー情報を取得
|
|
72
|
+
*
|
|
73
|
+
* @param {string} idToken - ユーザートークン
|
|
74
|
+
* @returns {GoogleAuthResult}
|
|
75
|
+
*/
|
|
76
|
+
export declare const getGoogleAuthResult: (idToken: string) => GoogleAuthResult;
|
|
65
77
|
export declare const getAccessToken: (config: GetAccessTokenConfig) => Promise<string>;
|
|
78
|
+
export declare const effect_googleAuth: <S>(props: {
|
|
79
|
+
state: S;
|
|
80
|
+
config: GoogleAuthConfig;
|
|
81
|
+
renderButton?: HTMLElement;
|
|
82
|
+
renderOptions?: {
|
|
83
|
+
theme?: "outline" | "filled_blue" | "filled_black";
|
|
84
|
+
size?: "large" | "medium" | "small";
|
|
85
|
+
text?: "signin_with" | "signup_with" | "continue_with";
|
|
86
|
+
shape?: "rectangular" | "pill" | "circle" | "square";
|
|
87
|
+
};
|
|
88
|
+
onLoad: (state: S, res: GoogleAuthResult) => S | [S, Effect<S>];
|
|
89
|
+
}) => (dispatch: Dispatch<S>) => Promise<void>;
|
|
90
|
+
export declare const googleLogout: (hint: string) => void;
|
|
@@ -1,12 +1,17 @@
|
|
|
1
|
-
//
|
|
2
|
-
//
|
|
3
|
-
//
|
|
4
|
-
//
|
|
1
|
+
// ========== ========== ========== ========== ==========
|
|
2
|
+
// import
|
|
3
|
+
// ========== ========== ========== ========== ==========
|
|
4
|
+
// ========== ========== ========== ========== ==========
|
|
5
|
+
// procedure
|
|
6
|
+
// ========== ========== ========== ========== ==========
|
|
7
|
+
// ---------- ---------- ---------- ---------- ----------
|
|
5
8
|
// getGoogle
|
|
6
|
-
// ---------- ---------- ----------
|
|
9
|
+
// ---------- ---------- ---------- ---------- ----------
|
|
7
10
|
// 2重読み込み防止用の変数
|
|
8
11
|
let googlePromise = null;
|
|
9
|
-
|
|
12
|
+
/**
|
|
13
|
+
* Google 変数を取得する
|
|
14
|
+
*/
|
|
10
15
|
export const getGoogle = async () => {
|
|
11
16
|
if (window.google)
|
|
12
17
|
return window.google;
|
|
@@ -35,55 +40,33 @@ export const getGoogle = async () => {
|
|
|
35
40
|
return googlePromise;
|
|
36
41
|
};
|
|
37
42
|
// ---------- ---------- ---------- ---------- ----------
|
|
38
|
-
//
|
|
43
|
+
// getGoogleAuthResult
|
|
39
44
|
// ---------- ---------- ---------- ---------- ----------
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
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 });
|
|
74
|
-
}
|
|
75
|
-
catch (error) {
|
|
76
|
-
reject(error);
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
}); // end initialize
|
|
80
|
-
// show prompt
|
|
81
|
-
client.prompt((notification) => {
|
|
82
|
-
if (notification.isNotDisplayed() || notification.isSkippedMoment()) {
|
|
83
|
-
resolve(null);
|
|
84
|
-
}
|
|
85
|
-
});
|
|
86
|
-
}); // end result
|
|
45
|
+
/**
|
|
46
|
+
* idToken から ユーザー情報を取得
|
|
47
|
+
*
|
|
48
|
+
* @param {string} idToken - ユーザートークン
|
|
49
|
+
* @returns {GoogleAuthResult}
|
|
50
|
+
*/
|
|
51
|
+
export const getGoogleAuthResult = (idToken) => {
|
|
52
|
+
const base64 = idToken.split(".")[1]
|
|
53
|
+
.replace(/-/g, "+")
|
|
54
|
+
.replace(/_/g, "/");
|
|
55
|
+
const decode = (str) => decodeURIComponent(atob(str)
|
|
56
|
+
.split("")
|
|
57
|
+
.map(c => "%" + ("00" + c.charCodeAt(0).toString(16)).slice(-2))
|
|
58
|
+
.join(""));
|
|
59
|
+
const payload = JSON.parse(decode(base64));
|
|
60
|
+
const user = {
|
|
61
|
+
name: payload.name,
|
|
62
|
+
email: payload.email,
|
|
63
|
+
picture: payload.picture,
|
|
64
|
+
sub: payload.sub
|
|
65
|
+
};
|
|
66
|
+
return {
|
|
67
|
+
idToken,
|
|
68
|
+
user
|
|
69
|
+
};
|
|
87
70
|
};
|
|
88
71
|
// ---------- ---------- ---------- ---------- ----------
|
|
89
72
|
// getAccessToken
|
|
@@ -116,3 +99,53 @@ export const getAccessToken = async (config) => {
|
|
|
116
99
|
tokenClient.requestAccessToken({ prompt }); // prompt == "none" のときには、事前にログインが必要
|
|
117
100
|
});
|
|
118
101
|
};
|
|
102
|
+
// ========== ========== ========== ========== ==========
|
|
103
|
+
// effect
|
|
104
|
+
// ========== ========== ========== ========== ==========
|
|
105
|
+
// ---------- ---------- ---------- ---------- ----------
|
|
106
|
+
// effect_googleAuth
|
|
107
|
+
// ---------- ---------- ---------- ---------- ----------
|
|
108
|
+
export const effect_googleAuth = function (props) {
|
|
109
|
+
// variable
|
|
110
|
+
const { state, config, renderButton, renderOptions, onLoad } = props;
|
|
111
|
+
// result
|
|
112
|
+
return async (dispatch) => {
|
|
113
|
+
// get google api
|
|
114
|
+
const google = await getGoogle();
|
|
115
|
+
// set renderButton
|
|
116
|
+
if (renderButton) {
|
|
117
|
+
google.accounts.id.renderButton(renderButton, renderOptions);
|
|
118
|
+
}
|
|
119
|
+
// get client
|
|
120
|
+
const client = google.accounts.id;
|
|
121
|
+
// initialize
|
|
122
|
+
client.initialize({
|
|
123
|
+
client_id: config.clientId,
|
|
124
|
+
auto_select: config.autoSelect,
|
|
125
|
+
ux_mode: config.uxMode,
|
|
126
|
+
callback: (response) => {
|
|
127
|
+
dispatch((state) => onLoad(state, getGoogleAuthResult(response.credential)));
|
|
128
|
+
}
|
|
129
|
+
});
|
|
130
|
+
// show prompt
|
|
131
|
+
client.prompt((notification) => {
|
|
132
|
+
if (notification.isNotDisplayed()) {
|
|
133
|
+
console.log("Google prompt not displayed");
|
|
134
|
+
}
|
|
135
|
+
if (notification.isSkippedMoment()) {
|
|
136
|
+
console.log("Google prompt skipped");
|
|
137
|
+
}
|
|
138
|
+
});
|
|
139
|
+
}; // end result
|
|
140
|
+
};
|
|
141
|
+
// ---------- ---------- ---------- ---------- ----------
|
|
142
|
+
// googleLogout
|
|
143
|
+
// ---------- ---------- ---------- ---------- ----------
|
|
144
|
+
export const googleLogout = (hint) => {
|
|
145
|
+
getGoogle().then(google => {
|
|
146
|
+
const client = google.accounts.id;
|
|
147
|
+
client.disableAutoSelect();
|
|
148
|
+
client.cancel();
|
|
149
|
+
client.revoke(hint, () => { });
|
|
150
|
+
});
|
|
151
|
+
};
|