mirror of
https://github.com/absmach/magistrala.git
synced 2026-08-07 07:14:46 +00:00
MG-3537 - Migrate Magistrala to ATOM for identity & authorization (#3532)
Property Based Tests / api-test (push) Has been cancelled
Continuous Delivery / lint-and-build (push) Has been cancelled
Deploy GitHub Pages / swagger-ui (push) Has been cancelled
CI Pipeline / Lint Proto (push) Has been cancelled
CI Pipeline / Detect Changes (push) Has been cancelled
Continuous Delivery / Build and Push Docker Images (push) Has been cancelled
CI Pipeline / lint-and-build (push) Has been cancelled
CI Pipeline / Test ${{ matrix.module }} (push) Has been cancelled
CI Pipeline / Upload Coverage (push) Has been cancelled
Property Based Tests / api-test (push) Has been cancelled
Continuous Delivery / lint-and-build (push) Has been cancelled
Deploy GitHub Pages / swagger-ui (push) Has been cancelled
CI Pipeline / Lint Proto (push) Has been cancelled
CI Pipeline / Detect Changes (push) Has been cancelled
Continuous Delivery / Build and Push Docker Images (push) Has been cancelled
CI Pipeline / lint-and-build (push) Has been cancelled
CI Pipeline / Test ${{ matrix.module }} (push) Has been cancelled
CI Pipeline / Upload Coverage (push) Has been cancelled
Signed-off-by: Arvindh <arvindh91@gmail.com> Signed-off-by: dusan <borovcanindusan1@gmail.com> Signed-off-by: Rodney Osodo <socials@rodneyosodo.com> Co-authored-by: Dušan Borovčanin <dusan.borovcanin@absmach.eu> Co-authored-by: Rodney Osodo <socials@rodneyosodo.com> Co-authored-by: dusan <borovcanindusan1@gmail.com>
This commit is contained in:
@@ -0,0 +1,37 @@
|
||||
// Copyright (c) Abstract Machines
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
package atom
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
atomcore "github.com/absmach/magistrala/internal/atom"
|
||||
"github.com/absmach/magistrala/pkg/authn"
|
||||
"github.com/absmach/magistrala/pkg/errors"
|
||||
svcerr "github.com/absmach/magistrala/pkg/errors/service"
|
||||
)
|
||||
|
||||
type authentication struct {
|
||||
verifier *atomcore.TokenVerifier
|
||||
}
|
||||
|
||||
var _ authn.Authentication = (*authentication)(nil)
|
||||
|
||||
func NewAuthentication() authn.Authentication {
|
||||
return authentication{verifier: atomcore.NewTokenVerifier(atomcore.LoadConfig())}
|
||||
}
|
||||
|
||||
func (a authentication) Authenticate(ctx context.Context, token string) (authn.Session, error) {
|
||||
claims, err := a.verifier.VerifyTokenClaims(ctx, token)
|
||||
if err != nil {
|
||||
return authn.Session{}, errors.Wrap(svcerr.ErrAuthentication, err)
|
||||
}
|
||||
return authn.Session{
|
||||
Type: authn.AccessToken,
|
||||
UserID: claims.SubjectID,
|
||||
DomainID: claims.TenantID,
|
||||
Role: authn.UserRole,
|
||||
Verified: true,
|
||||
}, nil
|
||||
}
|
||||
Reference in New Issue
Block a user