forked from taskcluster/taskcluster
-
Notifications
You must be signed in to change notification settings - Fork 0
/
auth.go
49 lines (38 loc) · 1.13 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
package mocktc
import (
"testing"
"time"
"github.com/golang-jwt/jwt/v4"
"github.com/taskcluster/taskcluster/v47/clients/client-go/tcauth"
)
type Auth struct {
}
/////////////////////////////////////////////////
const WST_SECRET = "sshhh!"
const WST_AUDIENCE = "testing"
func (auth *Auth) ExpandScopes(payload *tcauth.SetOfScopes) (*tcauth.SetOfScopes, error) {
return &tcauth.SetOfScopes{}, nil
}
func (auth *Auth) SentryDSN(project string) (*tcauth.SentryDSNResponse, error) {
return &tcauth.SentryDSNResponse{}, nil
}
func (auth *Auth) WebsocktunnelToken(wstAudience, wstClientId string) (*tcauth.WebsocktunnelTokenResponse, error) {
token, err := jwt.NewWithClaims(jwt.SigningMethodHS256, jwt.MapClaims{
"tid": wstClientId,
"iat": time.Now().Unix(),
"nbf": time.Now().Add(-1 * time.Minute).Unix(),
"exp": time.Now().Add(1 * time.Minute).Unix(),
"aud": WST_AUDIENCE,
}).SignedString([]byte(WST_SECRET))
if err != nil {
return nil, err
}
return &tcauth.WebsocktunnelTokenResponse{
Token: token,
}, nil
}
/////////////////////////////////////////////////
func NewAuth(t *testing.T) *Auth {
a := &Auth{}
return a
}