forked from microsoft/go-mssqldb
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaccesstokenconnector.go
More file actions
31 lines (25 loc) · 820 Bytes
/
accesstokenconnector.go
File metadata and controls
31 lines (25 loc) · 820 Bytes
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
// +build go1.10
package mssql
import (
"context"
"database/sql/driver"
"errors"
)
// NewAccessTokenConnector creates a new connector from a DSN and a token provider.
// The token provider func will be called when a new connection is requested and should return a valid access token.
// The returned connector may be used with sql.OpenDB.
func NewAccessTokenConnector(dsn string, tokenProvider func() (string, error)) (driver.Connector, error) {
if tokenProvider == nil {
return nil, errors.New("mssql: tokenProvider cannot be nil")
}
conn, err := NewConnector(dsn)
if err != nil {
return nil, err
}
conn.fedAuthRequired = true
conn.fedAuthLibrary = FedAuthLibrarySecurityToken
conn.securityTokenProvider = func(ctx context.Context) (string, error) {
return tokenProvider()
}
return conn, nil
}