-
Notifications
You must be signed in to change notification settings - Fork 0
/
auth.go
43 lines (36 loc) · 1.08 KB
/
auth.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package platform
import (
"context"
"errors"
"github.com/ogreks/meeseeks-box/internal/dao"
"github.com/ogreks/meeseeks-box/internal/domain"
"github.com/ogreks/meeseeks-box/internal/model"
"github.com/ogreks/meeseeks-box/internal/pkg/httpsign"
"github.com/ogreks/meeseeks-box/internal/pkg/httpsign/secret"
)
var (
ErrAppIdNotFound = errors.New("appid not found")
ErrAppDisabled = errors.New("appid is disable")
)
// DetailByAppID get session account by app id
func (s *service) DetailByAppID(ctx context.Context, appid string) (model.SessionKey, error) {
data, err := s.pDomain.SessionKey(ctx, dao.SessionKey.AppID.Eq(appid))
if errors.Is(err, domain.NotFound) {
err = ErrAppIdNotFound
}
return *data, err
}
// Secret give appid return secret
func (s *service) Secret(ctx context.Context, appid httpsign.KeyID) (*httpsign.Secret, error) {
data, err := s.DetailByAppID(ctx, string(appid))
if err != nil {
return nil, err
}
if data.IsEnabled == 0 {
return nil, ErrAppDisabled
}
return &httpsign.Secret{
Key: data.AppSecret,
Algorithm: &secret.HmacSha512{},
}, nil
}