Created
May 25, 2021 17:39
-
-
Save DavidWells/255d69f8d68c0f9e738240cda2373e7c to your computer and use it in GitHub Desktop.
Anonymous claiming of netlify sites
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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