-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathmain.go
More file actions
39 lines (32 loc) · 921 Bytes
/
main.go
File metadata and controls
39 lines (32 loc) · 921 Bytes
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
39
package main
import (
"github.com/go-martini/martini"
gooauth2 "github.com/golang/oauth2"
"github.com/martini-contrib/oauth2"
"github.com/martini-contrib/sessions"
)
func main() {
m := martini.Classic()
oauthOpts := &gooauth2.Options{
ClientID: "cf-go-client-example",
ClientSecret: "c1oudc0w",
RedirectURL: "https://cf-go-client-example.10.244.0.34.xip.io/oauth2callback",
Scopes: []string{""},
}
cf := oauth2.NewOAuth2Provider(oauthOpts, "https://login.10.244.0.34.xip.io/oauth/authorize",
"https://uaa.10.244.0.34.xip.io/oauth/token")
m.Handlers(
sessions.Sessions("my_session", sessions.NewCookieStore([]byte("secret123"))),
cf,
oauth2.LoginRequired,
martini.Logger(),
martini.Static("public"),
)
m.Get("/", func(tokens oauth2.Tokens) string {
if tokens.IsExpired() {
return "not logged in, or the access token is expired"
}
return "logged in"
})
m.Run()
}