add state to cookie so it can be confirmed in callback

shared-server
bat 3 years ago
parent 9b770cf95c
commit c207fcc949

@ -1,3 +1,5 @@
import * as cookie from 'https://deno.land/std@0.188.0/http/cookie.ts'
export class Auth { export class Auth {
constructor({ constructor({
baseUrl, baseUrl,
@ -25,14 +27,20 @@ export class Auth {
this.remoteBaseUrl + '/auth/callback' this.remoteBaseUrl + '/auth/callback'
) )
const timestamp = new Date().valueOf() const timestamp = new Date().valueOf()
const randomInt = Math.floor(Math.random() * 10000)
// TODO: sign // TODO: sign
const signedTimestamp = `${timestamp}` const state = `${randomInt}-${timestamp}`
search.set('state', signedTimestamp) search.set('state', state)
url.search = search.toString() url.search = search.toString()
const headers = new Headers({
Location: url.toString()
})
cookie.setCookie(headers, {
name: 'oauth.gitea.state',
value: state,
})
return new Response('', { return new Response('', {
headers: { headers,
Location: url.toString()
},
status: 302, status: 302,
}) })
} }

Loading…
Cancel
Save