mirror of
https://github.com/mainflux/mainflux.git
synced 2025-05-02 22:17:10 +08:00

* Update Go version Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com> * Update dependencies Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com>
51 lines
1020 B
Go
51 lines
1020 B
Go
// Copyright (c) Mainflux
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
|
|
package grpc
|
|
|
|
import (
|
|
"context"
|
|
"time"
|
|
|
|
"github.com/go-kit/kit/endpoint"
|
|
"github.com/mainflux/mainflux/authn"
|
|
)
|
|
|
|
func issueEndpoint(svc authn.Service) endpoint.Endpoint {
|
|
return func(ctx context.Context, request interface{}) (interface{}, error) {
|
|
req := request.(issueReq)
|
|
if err := req.validate(); err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
now := time.Now().UTC()
|
|
key := authn.Key{
|
|
Type: req.keyType,
|
|
IssuedAt: now,
|
|
}
|
|
|
|
k, err := svc.Issue(ctx, req.issuer, key)
|
|
if err != nil {
|
|
return identityRes{}, err
|
|
}
|
|
|
|
return identityRes{k.Secret, nil}, nil
|
|
}
|
|
}
|
|
|
|
func identifyEndpoint(svc authn.Service) endpoint.Endpoint {
|
|
return func(ctx context.Context, request interface{}) (interface{}, error) {
|
|
req := request.(identityReq)
|
|
if err := req.validate(); err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
id, err := svc.Identify(ctx, req.token)
|
|
if err != nil {
|
|
return identityRes{}, err
|
|
}
|
|
|
|
return identityRes{id, nil}, nil
|
|
}
|
|
}
|