summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlexander Rakoczy <arakoczy@gmail.com>2020-07-26 16:06:08 -0400
committerAlexander Rakoczy <arakoczy@gmail.com>2020-07-26 16:06:08 -0400
commit02b3f6aead7cfcd929b3469f2acb4891f7b5177d (patch)
treebbc92bc46bdda567262610aaeaca6f511dc267a5
parentaf21f90acd9f90ab73d1b29209ad12816905830c (diff)
FROGS EVERYWHERE
-rw-r--r--frogslack.go44
-rw-r--r--go.mod10
-rw-r--r--go.sum21
3 files changed, 60 insertions, 15 deletions
diff --git a/frogslack.go b/frogslack.go
index 0a3f1aa..7291140 100644
--- a/frogslack.go
+++ b/frogslack.go
@@ -6,6 +6,7 @@ import (
"errors"
"io/ioutil"
"net/http"
+ "net/url"
"os"
"github.com/golang/glog"
@@ -20,6 +21,8 @@ const (
var (
apiUrl = "https://frog.tips/api/1/tips"
signingSecret = os.Getenv("SLACK_SIGNING_SECRET_SHH")
+ clientId = os.Getenv("SLACK_CLIENT_ID")
+ clientSecret = os.Getenv("SLACK_CLIENT_SECRET")
)
type Attachment struct {
@@ -130,3 +133,44 @@ func writeResponse(w http.ResponseWriter, resp *Response) {
glog.Errorf("e.Encode(%#v) = _, %q", resp, err)
}
}
+
+type accessResp struct {
+ Ok bool `json:"ok"`
+ AppId string `json:"app_id"`
+ Error string `json:"error"`
+ Team struct {
+ Id string `json:"id"`
+ } `json:"team"`
+}
+
+func Hop(w http.ResponseWriter, r *http.Request) {
+ code := r.FormValue("code")
+ resp, err := http.PostForm("https://slack.com/api/oauth.v2.access", url.Values{
+ "code": []string{code},
+ "client_id": []string{clientId},
+ "client_secret": []string{clientSecret},
+ "redirect_uri": []string{""},
+ })
+ if err != nil {
+ glog.Errorf("what hath god wrought: %v", err)
+ return
+ }
+ defer resp.Body.Close()
+ glog.Infof("hop'd: %v", resp.StatusCode)
+ body, err := ioutil.ReadAll(resp.Body)
+ if err != nil {
+ glog.Errorf("nobody %v", err)
+ return
+ }
+ var ar accessResp
+ if err := json.Unmarshal(body, &ar); err != nil {
+ glog.Errorf("its not even jason: %v", err)
+ return
+ }
+ glog.Infof("ok: %q, appId: %q, error: %q, Team: %+v", ar.Ok, ar.AppId, ar.Error, ar.Team)
+ if !ar.Ok {
+ w.Write([]byte("dang"))
+ return
+ }
+ w.Write([]byte("it's fine."))
+}
diff --git a/go.mod b/go.mod
index 584f617..c190daf 100644
--- a/go.mod
+++ b/go.mod
@@ -1,12 +1,12 @@
module github.com/toothrot/frogslack
+go 1.13
+
require (
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b
github.com/google/go-cmp v0.2.0
- github.com/gorilla/websocket v1.4.0 // indirect
- github.com/lusis/go-slackbot v0.0.0-20180109053408-401027ccfef5 // indirect
- github.com/lusis/slack-test v0.0.0-20180109053238-3c758769bfa6 // indirect
- github.com/nlopes/slack v0.5.0
- github.com/pkg/errors v0.8.1 // indirect
+ github.com/gorilla/websocket v1.4.2 // indirect
+ github.com/nlopes/slack v0.6.0
+ github.com/pkg/errors v0.9.1 // indirect
github.com/stretchr/testify v1.3.0 // indirect
)
diff --git a/go.sum b/go.sum
index 80e3568..4a72e81 100644
--- a/go.sum
+++ b/go.sum
@@ -1,21 +1,22 @@
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
+github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
+github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b h1:VKtxabqXZkF25pY9ekfRL6a582T4P37/31XEstQ5p58=
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q=
github.com/google/go-cmp v0.2.0 h1:+dTQ8DZQJz0Mb/HjFlkptS1FeQ4cWSnN941F8aEG4SQ=
github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M=
-github.com/gorilla/websocket v1.4.0 h1:WDFjx/TMzVgy9VdMMQi2K2Emtwi2QcUQsztZ/zLaH/Q=
-github.com/gorilla/websocket v1.4.0/go.mod h1:E7qHFY5m1UJ88s3WnNqhKjPHQ0heANvMoAMk2YaljkQ=
-github.com/lusis/go-slackbot v0.0.0-20180109053408-401027ccfef5 h1:AsEBgzv3DhuYHI/GiQh2HxvTP71HCCE9E/tzGUzGdtU=
-github.com/lusis/go-slackbot v0.0.0-20180109053408-401027ccfef5/go.mod h1:c2mYKRyMb1BPkO5St0c/ps62L4S0W2NAkaTXj9qEI+0=
-github.com/lusis/slack-test v0.0.0-20180109053238-3c758769bfa6 h1:iOAVXzZyXtW408TMYejlUPo6BIn92HmOacWtIfNyYns=
-github.com/lusis/slack-test v0.0.0-20180109053238-3c758769bfa6/go.mod h1:sFlOUpQL1YcjhFVXhg1CG8ZASEs/Mf1oVb6H75JL/zg=
-github.com/nlopes/slack v0.5.0 h1:NbIae8Kd0NpqaEI3iUrsuS0KbcEDhzhc939jLW5fNm0=
-github.com/nlopes/slack v0.5.0/go.mod h1:jVI4BBK3lSktibKahxBF74txcK2vyvkza1z/+rRnVAM=
-github.com/pkg/errors v0.8.1 h1:iURUrRGxPUNPdy5/HRSm+Yj6okJ6UtLINN0Q9M4+h3I=
-github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
+github.com/gorilla/websocket v1.2.0/go.mod h1:E7qHFY5m1UJ88s3WnNqhKjPHQ0heANvMoAMk2YaljkQ=
+github.com/gorilla/websocket v1.4.2 h1:+/TMaTYc4QFitKJxsQ7Yye35DkWvkdLcvGKqM+x0Ufc=
+github.com/gorilla/websocket v1.4.2/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
+github.com/nlopes/slack v0.6.0 h1:jt0jxVQGhssx1Ib7naAOZEZcGdtIhTzkP0nopK0AsRA=
+github.com/nlopes/slack v0.6.0/go.mod h1:JzQ9m3PMAqcpeCam7UaHSuBuupz7CmpjehYMayT6YOk=
+github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
+github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
+github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
+github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0Q=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=