Skip to content

Commit

Permalink
Added lambda and redirect page
Browse files Browse the repository at this point in the history
  • Loading branch information
hannesrabo committed Apr 18, 2019
1 parent 1117583 commit d1089d2
Show file tree
Hide file tree
Showing 3 changed files with 161 additions and 0 deletions.
1 change: 1 addition & 0 deletions ..-
Submodule ..- added at a1d933
71 changes: 71 additions & 0 deletions lambda.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
const https = require('https')

exports.handler = function(event, context) {
// https://lambda/?code=xxx&state=
// If this is the initial request.
if (event.httpMethod === 'GET' && event.queryStringParameters.code) {
// Retrieve the initial auth
// https://slack.com/api/oauth.access?client_id&client_secret&code
let { client_id, client_secret } = process.env

const optionspost = {
host: 'slack.com',
path: `/api/oauth.access?client_id=${client_id}&client_secret=${client_secret}&code=${
event.queryStringParameters.code
}`,
method: 'GET'
}

let body = ''

var reqPost = https
.request(optionspost, function(res) {
res.on('data', function(chunk) {
body += chunk
})

res.on('end', function() {
let jsonStr = JSON.parse(body)

// {"ok":true,
// "access_token":"xoxp-xxx-xxx-xxx",
// "scope":"identify,incoming-webhook,chat:write:bot",
// "user_id":"xxx","team_name":"xxx","team_id":"xxx"}
if (jsonStr.ok) {
context.succeed({
statusCode: 200,
body: JSON.stringify({
ok: true,
access_token: jsonStr.access_token
})
})
} else {
context.succeed({
statusCode: 401,
body: JSON.stringify({
ok: false,
message: 'Invalid credentials'
})
})
}
})
})
.on('error', function(e) {
context.succeed({
statusCode: 500,
body: JSON.stringify({
ok: false,
message: 'Could not connect to slack.'
})
})
})

reqPost.write('')
reqPost.end()
} else {
context.succeed({
statusCode: 400,
body: JSON.stringify({ ok: false, message: 'Invalid request.' })
})
}
}
89 changes: 89 additions & 0 deletions wiki/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta http-equiv="X-UA-Compatible" content="ie=edge" />
<title>Semantic Releaser</title>

<style>
@font-face {
font-family: 'emoji';
src: url('emojione-svg.woff2') format('woff2');
}
.wrapper {
width: 80%;
margin: 100px auto;
display: flex;
justify-content: center;
flex-wrap: wrap;
}
h1 {
width: 60%;
margin-bottom: 50px;
font-size: 250%;
}
.input-container {
width: 60%;
display: flex;
}
p {
width: 60%;
margin-top: 50px;
}
.input-container div {
width: 10%;
color: white;
cursor: pointer;
background-color: lightseagreen;
border: 1px solid lightseagreen;
font-size: 170%;
text-align: center;
box-sizing: border-box;
}
.input-container div:hover {
border: 1px solid lightseagreen;
color: lightseagreen;
background-color: white;
}
input {
width: 90%;
font-size: 250%;
border: 1px solid lightseagreen;
}
</style>
</head>
<body>
<div class="wrapper">
<h1>📦🚀 Semantic Releaser</h1>
<div class="input-container">
<input type="text" id="input-field" value="..." />
<div id="copy-button"></div>
</div>
<p>
Copy the publish url and paste it into your config. This is a
private value, do not share it with anyone you do not trust.
</p>
</div>
</body>

<script>
function buttonClick(event) {
document.querySelector('#input-field').select()
document.execCommand('copy')
}

function fieldClick(event) {
document.querySelector('#input-field').select()
}

const urlParams = new URLSearchParams(window.location.search)
const token = urlParams.get('access_token')
let field = document.querySelector('#input-field')
field.value = token
field.addEventListener('click', fieldClick)

let button = document.querySelector('#copy-button')
button.addEventListener('click', buttonClick)
</script>
</html>

0 comments on commit d1089d2

Please sign in to comment.