This repository was archived by the owner on Feb 8, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathauth.go
More file actions
58 lines (49 loc) · 1.23 KB
/
auth.go
File metadata and controls
58 lines (49 loc) · 1.23 KB
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
package ot
import (
"context"
"time"
"github.com/itcomusic/ot/pkg/oscript"
)
const authService = "Authentication"
// GetToken creates token.
func (s *Session) GetToken(ctx context.Context, username, password string) (string, error) {
c, err := s.connect(ctx)
if err != nil {
return "", err
}
defer c.Close()
var t string
if err := errIn(c.Exec(authService, "AuthenticateUser", s.auth, oscript.M{
"userName": username,
"userPassword": password,
}, &t)); err != nil {
return "", err
}
return t, nil
}
// RefreshToken refreshes or creates token.
func (s *Session) RefreshToken(ctx context.Context) (string, error) {
c, err := s.connect(ctx)
if err != nil {
return "", err
}
defer c.Close()
var t string
if err := errIn(c.Exec(authService, "RefreshToken", s.auth, oscript.M{}, &t)); err != nil {
return "", err
}
return t, nil
}
// GetSessionExpiration returns expiration time.
func (s *Session) GetSessionExpiration(ctx context.Context) (time.Time, error) {
c, err := s.connect(ctx)
if err != nil {
return time.Time{}, err
}
defer c.Close()
var t time.Time
if err := errIn(c.Exec(authService, "GetSessionExpirationDate", s.auth, oscript.M{}, &t)); err != nil {
return time.Time{}, err
}
return t, nil
}