-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
40 lines (31 loc) · 820 Bytes
/
main.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
39
40
package main
import (
"github.com/kataras/iris"
jose "gopkg.in/square/go-jose.v2"
"crypto/rsa"
"crypto/rand"
"log"
)
func getWellKnown(ctx iris.Context) {
ctx.Writef("well-known")
}
func main() {
app := iris.New()
privateKey, err := rsa.GenerateKey(rand.Reader, 2048)
if err != nil {
log.Fatalf("Generating random key: %v", err)
}
key := jose.SigningKey{Algorithm: jose.RS256, Key: privateKey}
signerOpts := jose.SignerOptions{}
signerOpts.WithType("JWT")
rsaSigner, err := jose.NewSigner(key, &signerOpts)
if err != nil {
log.Fatalf("failed to create signer: %+v", err)
}
/* Unauthenticated routes go here */
app.Get("/.well-known/jwks", getWellKnown)
app.Get("/connect/token", getToken(rsaSigner))
/* Authenticate */
/* JWT Authenticated routes here */
app.Run(iris.Addr(":8008"))
}