-
Notifications
You must be signed in to change notification settings - Fork 3
/
auth_test.go
57 lines (45 loc) · 1.31 KB
/
auth_test.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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
package device_test
import (
"context"
"flag"
"os"
"testing"
"github.com/stretchr/testify/require"
"github.com/rockset/device-authorization"
)
var integrationFlag = flag.Bool("integration", false, "only perform local tests")
func integration(t *testing.T) {
if !*integrationFlag {
t.Skipf("skipping integration test")
}
}
func TestAuth0Auth(t *testing.T) {
integration(t)
ctx := context.TODO()
p := device.NewProvider("auth0")
a := device.NewAuthorizer(p.Config("rockset", os.Getenv("AUTH0_CLIENT_ID")))
code, err := a.RequestCode(ctx)
require.NoError(t, err)
t.Logf("%+v", code)
t.Logf("%s %s", code.DeviceCode, code.UserCode)
t.Logf("%s", code.VerificationURI)
t.Logf("%s", code.VerificationURIComplete)
token, err := a.WaitForAuthorization(ctx, code)
require.NoError(t, err)
t.Logf("token: %+v", token)
}
func TestOktaAuth(t *testing.T) {
integration(t)
ctx := context.TODO()
p := device.NewProvider("okta")
a := device.NewAuthorizer(p.Config("rockset", os.Getenv("OKTA_CLIENT_ID")))
code, err := a.RequestCode(ctx)
require.NoError(t, err)
t.Logf("%+v", code)
t.Logf("%s %s", code.DeviceCode, code.UserCode)
t.Logf("%s", code.VerificationURI)
t.Logf("%s", code.VerificationURIComplete)
token, err := a.WaitForAuthorization(ctx, code)
require.NoError(t, err)
t.Logf("token: %+v", token)
}