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
package remote
import (
"context"
"fmt"
"time"
"github.com/johnandersen777/socialweb-computer-kcp/internal/contract/pds"
)
var _ pds.ServiceAuth = (*ServiceAuth)(nil)
type ServiceAuth struct {
host *Host
scope []string
}
func (h *Host) ServiceAuth(scope []string) *ServiceAuth {
return &ServiceAuth{host: h, scope: scope}
}
func (s *ServiceAuth) ServiceAuth(ctx context.Context, did, audience, lxm string, expires time.Time) (string, error) {
if err := inScope(s.scope, did); err != nil {
return "", err
}
client, ok := s.host.held(did)
if !ok {
return "", fmt.Errorf("%w: no session is held for %s", pds.ErrNotFound, did)
}
return client.ServiceAuth(ctx, audience, lxm, expires)
}