1
0
mirror of https://github.com/mainflux/mainflux.git synced 2025-04-28 13:48:49 +08:00
Mirko Teodorovic 47217cb5b9
NOISSUE - Merge authz and authn into new service auth (#1313)
* remove owner id

Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com>

* move authz into authn and merge into new service

Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com>

* add groups

Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com>

* add groups

Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com>

* add groups endpoints

Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com>

* add group type

Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com>

* adding mocks, some renaming, refactor

Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com>

* update proto

Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com>

* adding mocks, some renaming, refactor

Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com>

* fix linter err,and comments

Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com>

* undo renaming, add interface for authn and authz

Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com>

* renam some variables

Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com>

* renaming

Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com>

* remove extra slashes from comment

Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com>

* resolving small remarks

Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com>
2020-12-29 23:02:35 +01:00

73 lines
2.0 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"
"errors"
"time"
"github.com/golang/protobuf/ptypes/empty"
"github.com/mainflux/mainflux/things"
"github.com/mainflux/mainflux"
"google.golang.org/grpc"
)
var (
errUnsupported = errors.New("not supported in single user mode")
)
var _ mainflux.AuthServiceClient = (*singleUserRepo)(nil)
type singleUserRepo struct {
email string
token string
}
// NewSingleUserService creates single user repository for constrained environments.
func NewSingleUserService(email, token string) mainflux.AuthServiceClient {
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
}
func (repo singleUserRepo) Authorize(ctx context.Context, req *mainflux.AuthorizeReq, _ ...grpc.CallOption) (r *mainflux.AuthorizeRes, err error) {
return &mainflux.AuthorizeRes{}, errUnsupported
}
func (repo singleUserRepo) Members(ctx context.Context, req *mainflux.MembersReq, _ ...grpc.CallOption) (r *mainflux.MembersRes, err error) {
return &mainflux.MembersRes{}, errUnsupported
}
func (repo singleUserRepo) Assign(ctx context.Context, req *mainflux.Assignment, _ ...grpc.CallOption) (r *empty.Empty, err error) {
return &empty.Empty{}, errUnsupported
}