mirror of
https://github.com/cubefs/cubefs.git
synced 2026-08-02 02:00:56 +00:00
46 lines
1.2 KiB
Go
46 lines
1.2 KiB
Go
package auth
|
|
|
|
import (
|
|
"encoding/json"
|
|
|
|
"github.com/cubefs/cubefs/proto"
|
|
"github.com/cubefs/cubefs/util/auth"
|
|
"github.com/cubefs/cubefs/util/cryptoutil"
|
|
)
|
|
|
|
func (api *API) GetTicket(clientId string, clientKey string, serviceID string) (ticket *auth.Ticket, err error) {
|
|
var (
|
|
key []byte
|
|
ts int64
|
|
msgResp proto.AuthGetTicketResp
|
|
respData []byte
|
|
)
|
|
message := proto.AuthGetTicketReq{
|
|
Type: proto.MsgAuthTicketReq,
|
|
ClientID: clientId,
|
|
ServiceID: serviceID,
|
|
}
|
|
if key, err = cryptoutil.Base64Decode(clientKey); err != nil {
|
|
return
|
|
}
|
|
if message.Verifier, ts, err = cryptoutil.GenVerifier(key); err != nil {
|
|
return
|
|
}
|
|
if respData, err = api.ac.request(clientId, clientKey, key, message, proto.ClientGetTicket, serviceID); err != nil {
|
|
return
|
|
}
|
|
if err = json.Unmarshal(respData, &msgResp); err != nil {
|
|
return
|
|
}
|
|
if err = proto.VerifyTicketRespComm(&msgResp, proto.MsgAuthTicketReq, clientId, serviceID, ts); err != nil {
|
|
return
|
|
}
|
|
ticket = &auth.Ticket{
|
|
ID: clientId,
|
|
SessionKey: cryptoutil.Base64Encode(msgResp.SessionKey.Key),
|
|
ServiceID: cryptoutil.Base64Encode(msgResp.SessionKey.Key),
|
|
Ticket: msgResp.Ticket,
|
|
}
|
|
return
|
|
}
|