Skip to content

Instantly share code, notes, and snippets.

@DavidWells
Created May 25, 2021 17:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DavidWells/255d69f8d68c0f9e738240cda2373e7c to your computer and use it in GitHub Desktop.
Save DavidWells/255d69f8d68c0f9e738240cda2373e7c to your computer and use it in GitHub Desktop.
Anonymous claiming of netlify sites
const jwt = require('jsonwebtoken')
const {
NETLIFY_OAUTH_CLIENT_ID,
NETLIFY_OAUTH_CLIENT_SECRET
} = process.env
/* Function to handle netlify auth callback */
module.exports.handler = async (event, context) => {
const body = JSON.parse(event.body)
const { sessionId } = body
if (!sessionId) {
return {
statusCode: 401,
body: JSON.stringify({
message: 'missing session id'
})
}
}
const token = jwt.sign({
client_id: NETLIFY_OAUTH_CLIENT_ID,
session_id: sessionId,
}, NETLIFY_OAUTH_CLIENT_SECRET)
const claimUrl = `https://app.netlify.com/claim#${token}`
console.log('Link to claim your sites:')
console.log(claimUrl)
return {
statusCode: 200,
body: JSON.stringify({
sessionId: sessionId,
claim: claimUrl
})
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment