-
Notifications
You must be signed in to change notification settings - Fork 0
/
auth.go
38 lines (32 loc) · 925 Bytes
/
auth.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
package cliauth
import (
"crypto/rand"
"encoding/base64"
"net/http"
"time"
"golang.org/x/oauth2"
)
func NewAuthConfig() *oauth2.Config {
return &oauth2.Config{
ClientID: "77sr88lvofdg37lptf4r402nf1",
Scopes: []string{"openid", "email"},
Endpoint: oauth2.Endpoint{
AuthURL: "https://common-fate-registry.auth.us-west-2.amazoncognito.com/oauth2/authorize",
TokenURL: "https://common-fate-registry.auth.us-west-2.amazoncognito.com/oauth2/token",
},
RedirectURL: "http://localhost:8848/oauth/login/callback",
}
}
func generateStateOauthCookie(w http.ResponseWriter) string {
var expiration = time.Now().Add(20 * time.Minute)
b := make([]byte, 16)
_, err := rand.Read(b)
if err != nil {
// shouldn't happen
panic(err)
}
state := base64.URLEncoding.EncodeToString(b)
cookie := http.Cookie{Name: "oauthstate", Value: state, Expires: expiration}
http.SetCookie(w, &cookie)
return state
}