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>
54 lines
1.3 KiB
Go
54 lines
1.3 KiB
Go
// Copyright (c) Mainflux
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
|
|
// Package users contains implementation for users service in
|
|
// single user scenario.
|
|
package users
|
|
|
|
import (
|
|
"context"
|
|
"time"
|
|
|
|
"github.com/mainflux/mainflux/things"
|
|
|
|
"github.com/mainflux/mainflux"
|
|
"google.golang.org/grpc"
|
|
)
|
|
|
|
var _ mainflux.AuthNServiceClient = (*singleUserRepo)(nil)
|
|
|
|
type singleUserRepo struct {
|
|
email string
|
|
token string
|
|
}
|
|
|
|
// NewSingleUserService creates single user repository for constrained environments.
|
|
func NewSingleUserService(email, token string) mainflux.AuthNServiceClient {
|
|
return singleUserRepo{
|
|
email: email,
|
|
token: token,
|
|
}
|
|
}
|
|
|
|
func (repo singleUserRepo) Issue(ctx context.Context, req *mainflux.IssueReq, opts ...grpc.CallOption) (*mainflux.Token, error) {
|
|
ctx, cancel := context.WithTimeout(ctx, time.Second)
|
|
defer cancel()
|
|
|
|
if repo.token != req.GetEmail() {
|
|
return nil, things.ErrUnauthorizedAccess
|
|
}
|
|
|
|
return &mainflux.Token{Value: repo.token}, nil
|
|
}
|
|
|
|
func (repo singleUserRepo) Identify(ctx context.Context, token *mainflux.Token, opts ...grpc.CallOption) (*mainflux.UserIdentity, error) {
|
|
ctx, cancel := context.WithTimeout(ctx, time.Second)
|
|
defer cancel()
|
|
|
|
if repo.token != token.GetValue() {
|
|
return nil, things.ErrUnauthorizedAccess
|
|
}
|
|
|
|
return &mainflux.UserIdentity{Id: repo.email, Email: repo.email}, nil
|
|
}
|