Skip to content

Commit 0eae2e7

Browse files
authored
Merge pull request #1528 from 0chain/fix/auth-ticket-enterprise
Fix/auth ticket enterprise
2 parents f69d989 + 06d5ad9 commit 0eae2e7

File tree

1 file changed

+25
-11
lines changed

1 file changed

+25
-11
lines changed

code/go/0chain.net/blobbercore/handler/auth_ticket.go

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,12 @@ package handler
22

33
import (
44
"context"
5+
"fmt"
6+
"github.com/0chain/blobber/code/go/0chain.net/core/logging"
57
"github.com/0chain/blobber/code/go/0chain.net/core/node"
68
"github.com/0chain/common/core/common"
9+
"github.com/0chain/gosdk/core/encryption"
10+
"go.uber.org/zap"
711
"net/http"
812
)
913

@@ -19,28 +23,38 @@ type AuthTicketResponse struct {
1923
//
2024
// parameters:
2125
//
22-
// +name: Zbox-Signature
23-
// in: header
24-
// type: string
25-
// description: Digital signature to verify that the sender is 0box service.
26-
// +name: client_id
27-
// type: string
28-
// in: query
29-
// description: Client ID is used as a payload to the token generated. The token represents a signed version of this string by the blobber's private key.
26+
// +name: Zbox-Signature
27+
// in: header
28+
// type: string
29+
// description: Digital signature to verify that the sender is 0box service.
30+
// +name: client_id
31+
// type: string
32+
// in: query
33+
// description: Client ID is used as a payload to the token generated. The token represents a signed version of this string by the blobber's private key.
3034
//
3135
// responses:
32-
// 200: AuthTicketResponse
36+
//
37+
// 200: AuthTicketResponse
3338
func GenerateAuthTicket(ctx context.Context, r *http.Request) (interface{}, error) {
39+
3440
clientID := r.URL.Query().Get("client_id")
3541
if clientID == "" {
3642
return nil, common.NewError("missing_client_id", "client_id is required")
3743
}
3844

39-
signature, err := node.Self.Sign(clientID)
45+
round := r.URL.Query().Get("round")
46+
if round == "" {
47+
return nil, common.NewError("missing_round", "round is required")
48+
}
49+
50+
payload := encryption.Hash(fmt.Sprintf("%s_%s", clientID, round))
51+
52+
logging.Logger.Info("GenerateAuthTicket", zap.String("payload", payload), zap.String("client_id", clientID), zap.String("round", round))
53+
54+
signature, err := node.Self.Sign(payload)
4055
if err != nil {
4156
return nil, common.NewError("signature_failed", "signature failed")
4257
}
43-
4458
return &AuthTicketResponse{
4559
AuthTicket: signature,
4660
}, nil

0 commit comments

Comments
 (0)