-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcore.go
98 lines (79 loc) · 1.71 KB
/
core.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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
package OpenIDConnect
import (
"encoding/json"
"errors"
"fmt"
"strings"
"time"
"github.com/gocraft/web"
)
var (
ErrInvalidKey = errors.New("key is invalid or of invalid type")
ErrHashUnavailable = errors.New("the requested hash function is unavailable")
)
//New initialise App context
func New(s Storage) *App {
return &App{Storage: s, Config: s.getConfig()}
}
//App main app context
type App struct {
Storage Storage
Config Config
}
//Config of App
type Config struct {
domain string
}
//Client -> oidApplications
type Client struct {
Name string
}
//AccessToken -> oid token
type AccessToken struct {
Client string
User string
Token string
RefreshToken string //Optional
Expire string //Optional
CreatedAt string
}
//jwks (public rsa key)
func (a *App) jwks(rw web.ResponseWriter, r *web.Request) {
data := map[string]string{
"kty": "RSA",
"alg": "RS256",
"kid": string(time.Now().Unix()),
"use": "sig"}
// "e": base64.StdEncoding.EncodeToString([]byte(string(RsaKey.PublicKey.E))),
// "n": base64.StdEncoding.EncodeToString([]byte(RsaKey.PublicKey.N.String()))}
js, _ := json.Marshal(data)
rw.Header().Set("Content-Type", "application/json")
fmt.Fprint(rw, string(js))
}
/////JWT
//Jwt struct
type Jwt struct {
Raw string
Header map[string]string
Claims map[string]string
Sign string
Valid bool
}
func parseJwt(jwts string) (*Jwt, error) {
parts := strings.Split(jwts, ".")
if len(parts) != 3 {
return nil, ErrInvalidKey
}
token := &Jwt{Raw: jwts}
return token, nil
}
func (jwt *Jwt) verify() bool {
return false
}
func (jwt *Jwt) encode() {
}
type jwtSignEngine interface {
verify(token string) bool
sign() string
algo() string
}