-
Notifications
You must be signed in to change notification settings - Fork 2
/
auth.go
83 lines (68 loc) · 1.92 KB
/
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
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
package upvsMock
import (
"fmt"
"net/http"
"time"
"github.com/dgrijalva/jwt-go"
"github.com/google/uuid"
"github.com/slovak-egov/einvoice/pkg/handlerutil"
)
func (a *App) handleLogin(res http.ResponseWriter, req *http.Request) error {
callback := req.URL.Query().Get("callback")
if callback == "" {
return handlerutil.NewBadRequestError("params.callback.missing")
}
userClaims := jwt.MapClaims{
"sub": "rc://sk/8314451298_tisici_janko",
"name": "Janko Tisíci",
"jti": uuid.New().String(),
"exp": time.Now().Unix() + 120*60*1000,
"scopes": []string{
"sktalk/receive",
"sktalk/receive_and_save_to_outbox",
"sktalk/save_to_outbox",
},
}
userToken := jwt.NewWithClaims(jwt.SigningMethodRS256, userClaims)
userToken.Header["alg"] = "RS256"
userTokenString, err := userToken.SignedString(a.OboTokenPrivate)
if err != nil {
return err
}
orgClaims := jwt.MapClaims{
"sub": "ico://sk/11190993",
"name": "PO 190993",
"jti": uuid.New().String(),
"exp": time.Now().Unix() + 120*60*1000,
"scopes": []string{
"sktalk/receive",
"sktalk/receive_and_save_to_outbox",
"sktalk/save_to_outbox",
},
}
orgToken := jwt.NewWithClaims(jwt.SigningMethodRS256, orgClaims)
userToken.Header["alg"] = "RS256"
orgTokenString, err := orgToken.SignedString(a.OboTokenPrivate)
if err != nil {
return err
}
_, err = res.Write([]byte(fmt.Sprintf(
"<!DOCTYPE html>"+
"<html>"+
"<body>"+
"<ul>"+
"<li><a href=\"%s?token=%s\">Janko Tisíci</a></li>"+
"<li><a href=\"%s?token=%s\">PO 190993</a></li>"+
"</ul>"+
"</body>"+
"</html>", callback, userTokenString, callback, orgTokenString)))
return err
}
func (a *App) handleLogout(res http.ResponseWriter, req *http.Request) error {
callback := req.URL.Query().Get("callback")
if callback == "" {
return handlerutil.NewBadRequestError("params.callback.missing")
}
http.Redirect(res, req, callback, http.StatusFound)
return nil
}