forked from mitchellh/go-bnet
-
Notifications
You must be signed in to change notification settings - Fork 1
/
endpoint.go
39 lines (33 loc) · 987 Bytes
/
endpoint.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
package bnet
import (
"fmt"
"strings"
"sync"
"golang.org/x/oauth2"
)
// The variables below synchronize access to register an endpoint as
// broken with the OAuth2 library. Battle.net uses a "broken" implementation
// of OAuth2.
var brokenLock sync.Mutex
var brokenMap = map[string]struct{}{}
// Endpoint returns the endpoint for the given region. This doesn't
// validate the region name so you must use one that is valid from Battle.net.
func Endpoint(region string) oauth2.Endpoint {
region = strings.ToLower(region)
domain := fmt.Sprintf("https://%s.battle.net/", region)
if region == "cn" {
domain = "https://www.battlenet.com.cn/"
}
// Register the broken provider
brokenLock.Lock()
defer brokenLock.Unlock()
if _, ok := brokenMap[domain]; !ok {
brokenMap[domain] = struct{}{}
oauth2.RegisterBrokenAuthHeaderProvider(domain)
}
// Build the endpoint
return oauth2.Endpoint{
AuthURL: domain + "oauth/authorize",
TokenURL: domain + "oauth/token",
}
}