You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
|
|
export class Auth {
|
|
|
|
|
constructor({
|
|
|
|
|
baseUrl,
|
|
|
|
|
remoteBaseUrl,
|
|
|
|
|
giteaAppBaseUrl,
|
|
|
|
|
giteaClientId,
|
|
|
|
|
giteaClientSecret
|
|
|
|
|
}) {
|
|
|
|
|
this.baseUrl = baseUrl
|
|
|
|
|
this.remoteBaseUrl = remoteBaseUrl
|
|
|
|
|
this.giteaAppBaseUrl = giteaAppBaseUrl
|
|
|
|
|
this.giteaClientId = giteaClientId
|
|
|
|
|
this.giteaClientSecret = giteaClientSecret
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async redirect(event) {
|
|
|
|
|
const url = new URL(
|
|
|
|
|
this.giteaAppBaseUrl + '/login/oauth/authorize'
|
|
|
|
|
)
|
|
|
|
|
const search = new URLSearchParams()
|
|
|
|
|
search.set('response_type', 'code')
|
|
|
|
|
search.set('client_id', this.giteaClientId)
|
|
|
|
|
search.set(
|
|
|
|
|
'redirect_uri',
|
|
|
|
|
this.remoteBaseUrl + '/auth/callback'
|
|
|
|
|
)
|
|
|
|
|
const timestamp = new Date().valueOf()
|
|
|
|
|
// TODO: sign
|
|
|
|
|
const signedTimestamp = `${timestamp}`
|
|
|
|
|
search.set('state', signedTimestamp)
|
|
|
|
|
url.search = search.toString()
|
|
|
|
|
return new Response('', {
|
|
|
|
|
headers: {
|
|
|
|
|
Location: url.toString()
|
|
|
|
|
},
|
|
|
|
|
status: 302,
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
}
|