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

* Add both an ID and an Email to API key requests Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com> * Use return UserIdentity response Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com> * Replace GetValue with GetEmail Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com> * Refactor Mainflux Key Add `Subject` field and reorganize Key manipulation. **Remove backward compatibility** Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com> * Fix service test Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com> * Fix DB tests Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com> * Fix API tests Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com> * Fix JWT tests Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com> * Uncomment and fix API tests Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com> * Fix SQL statements alignment Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com> * Fix Issue method docs Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com> * Fix Retrieve API and API docs Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com> * Update tests Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com>
58 lines
1.1 KiB
Go
58 lines
1.1 KiB
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,
|
|
Subject: req.email,
|
|
IssuerID: req.id,
|
|
IssuedAt: now,
|
|
}
|
|
|
|
_, secret, err := svc.Issue(ctx, "", key)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return issueRes{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 nil, err
|
|
}
|
|
|
|
ret := identityRes{
|
|
id: id.ID,
|
|
email: id.Email,
|
|
err: nil,
|
|
}
|
|
return ret, nil
|
|
}
|
|
}
|