cococore
cococore
Explore posts from servers
DDeno
Created by cococore on 10/6/2024 in #help
i trying to deploy deno2 . it fails
first deno.lock version is 4 but editor says it must be v3. after i change v4 to v3 it says deno.exit is not allowed
6 replies
DDeno
Created by cococore on 10/6/2024 in #help
Deno + Hono + React. Any example or tutorial?
I see on deno docs site only tutorial how to create react app using deno and oak. How about hono instead of oak? Is there any example or tutorial?
1 replies
HHono
Created by cococore on 10/4/2024 in #help
how check the param is present. const my_id = c.req.param('id')
Is there preferable way to check const my_id = c.req.param('id') is present in parameters of request?
3 replies
DDeno
Created by cococore on 6/14/2024 in #help
deno_kv_oauth + hono how to fetch data from google profile: state, plans, method names changing.
In code examples i found in internet, used methods which already not the part of deno_kv_oauth. 1. Is there examples how to manage data for case of google(actually i plan to implement use facebook for authentication too)? 2. Will the future versions of deno_kv_oauth have changes in method names and structure of the lib? Feel free to mention me. In advance thank you for your time. The attached code in file is my attempt to get data from google. At the moment it does not work. Here is shorten version.
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)
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)
13 replies