const oauth_config = createGoogleOAuthConfig({
redirectUri: "http://localhost:8000/callback",
scope: "https://www.googleapis.com/auth/userinfo.profile"
});
const app = new Hono()
let g_tokens:Tokens; // my weird attempt to store tokens somewhere before use inside different app.get..
app.get('/', async (c:Context) => {
const session_id = getSessionId(c.req.raw);
const is_signed_in = session_id !== undefined; //has session id cookie
// console.log({is_signed_in})
const access_token = g_tokens.accessToken;
// !!! how to get google user name or login from .profile using oauth2 deno library methods?
/* THIS IS OLD CODE PART, WITH DEPRECATED METHODS AND FOR GITHUB. was found in some examples.
const accessToken = is_signed_in
? await getSessionAccessToken(oauthClient, session_id)
: null;
const githubUser = accessToken ? await getGitHubUser(accessToken) : null;
*/
if (!is_signed_in) {
return c.html(`shortened`)
}
return c.html(`shortened`)
})
app.get("/callback", async (c:Context) => {
const { response, sessionId, tokens } = await handleCallback(c.req.raw, oauth_config);
g_tokens = {...tokens};
c.header("set-cookie", response.headers.get("set-cookie")!);
return c.redirect(response.headers.get("location")!, response.status as RedirectStatusCode);
});
Deno.serve(app.fetch)