Skip to content

Commit 1cf96d0

Browse files
committed
fix: flow oauth
1 parent f14f02b commit 1cf96d0

File tree

5 files changed

+14
-17
lines changed

5 files changed

+14
-17
lines changed

google-sheets/actions/oauth/callback.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ export default async function callback(
3535
scope: authResponse.scope,
3636
token_type: authResponse.token_type,
3737
tokenObtainedAt: Math.floor(Date.now() / 1000),
38+
clientSecret: clientSecret || "",
3839
});
3940

4041
if (returnUrl) {

google-sheets/actions/oauth/refreshToken.ts

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,31 +3,30 @@ import { CLIENT_ID } from "../../utils/constant.ts";
33

44
/**
55
* @name REFRESH_TOKEN
6-
* @title Refresh GitHub Token
7-
* @description Atualiza o token de acesso usando o refresh token existente
6+
* @title Refresh Google Sheets Token
7+
* @description Refresh the access token using the existing refresh token
88
*/
99
export default async function refreshToken(
1010
_: unknown,
1111
_req: Request,
1212
ctx: AppContext,
1313
) {
14-
const { authClient, refresh_token: _refresh_token } = ctx;
14+
const { authClient, refresh_token: _refresh_token, clientSecret } = ctx;
1515
const currentCtx = await ctx.getConfiguration();
1616

1717
const refresh_token = _refresh_token || currentCtx.refresh_token;
1818

1919
if (!refresh_token) {
2020
return {
2121
success: false,
22-
message:
23-
"Não há refresh token disponível. É necessário autenticar novamente.",
22+
message: "no refresh token",
2423
};
2524
}
2625

2726
try {
2827
const response = await authClient[`POST /token`]({
2928
client_id: CLIENT_ID,
30-
client_secret: "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",
29+
client_secret: clientSecret || "",
3130
refresh_token: refresh_token,
3231
redirect_uri: new URL("/oauth/callback", _req.url).href,
3332
grant_type: "refresh_token",
@@ -52,19 +51,19 @@ export default async function refreshToken(
5251

5352
return {
5453
success: true,
55-
message: "Token atualizado com sucesso",
54+
message: "token refreshed",
5655
expires_in: refreshResponse.expires_in,
5756
};
5857
} else {
5958
return {
6059
success: false,
61-
message: "Falha ao atualizar o token",
60+
message: "failed to refresh token",
6261
};
6362
}
6463
} catch (error: unknown) {
6564
return {
6665
success: false,
67-
message: `Erro ao atualizar o token: ${
66+
message: `error to refresh token: ${
6867
error instanceof Error ? error.message : String(error)
6968
}`,
7069
};

google-sheets/loaders/getValues.ts

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,10 @@ const loader = async (
5858

5959
if (!isTokenValid) {
6060
throw new Error(
61-
"Não foi possível obter um token válido. Autentique-se novamente.",
61+
"failed to get a valid token. please authenticate again.",
6262
);
6363
}
6464

65-
// Construindo a URL com query parameters
6665
const rangeWithParams = `${
6766
encodeURIComponent(range)
6867
}?majorDimension=${majorDimension}&valueRenderOption=${valueRenderOption}&dateTimeRenderOption=${dateTimeRenderOption}`;
@@ -79,20 +78,17 @@ const loader = async (
7978
const data = await response.json();
8079
return data;
8180
} catch (error) {
82-
console.error("Erro ao obter valores:", error);
81+
console.error("error to get values:", error);
8382

84-
// Verificar se o erro está relacionado a token expirado
8583
if (
8684
error instanceof Error &&
8785
(error.message.includes("401") ||
8886
error.message.includes("invalid_token") ||
8987
error.message.includes("expired"))
9088
) {
91-
// Tenta atualizar o token novamente no caso de falha específica de autenticação
9289
try {
9390
const isTokenRefreshed = await ensureValidToken(ctx);
9491
if (isTokenRefreshed) {
95-
// Token atualizado com sucesso, tenta a requisição novamente
9692
const rangeWithParams = `${
9793
encodeURIComponent(range)
9894
}?majorDimension=${majorDimension}&valueRenderOption=${valueRenderOption}&dateTimeRenderOption=${dateTimeRenderOption}`;
@@ -109,7 +105,7 @@ const loader = async (
109105
return data;
110106
}
111107
} catch (refreshError) {
112-
console.error("Falha ao renovar token:", refreshError);
108+
console.error("error to refresh token:", refreshError);
113109
}
114110
}
115111

google-sheets/mod.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ export interface Props {
1515
token_type?: string;
1616
refresh_token_expires_in?: number;
1717
tokenObtainedAt?: number;
18+
clientSecret?: string;
1819
}
1920

2021
export interface State extends Props {

google-sheets/utils/clientWithAutoRefresh.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ export function createClientWithAutoRefresh(ctx: AppContext) {
1313
const isValid = await ensureValidToken(ctx);
1414

1515
if (!isValid) {
16-
throw new Error("Não foi possível obter um token válido");
16+
throw new Error("failed to get a valid token");
1717
}
1818

1919
const config = await ctx.getConfiguration();

0 commit comments

Comments
 (0)