-
Notifications
You must be signed in to change notification settings - Fork 51
/
login.go
41 lines (33 loc) · 826 Bytes
/
login.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
package authutil
import (
"net/url"
"strings"
)
// BuildLoginURL constructs a URL + query string that can be used to
// initiate a user-facing login-flow from the CLI.
func BuildLoginURL(domain, clientID, callbackURL, state, connectionName, audience, prompt string, scopes []string) (string, error) {
q := url.Values{}
q.Add("client_id", clientID)
q.Add("response_type", "code")
q.Add("redirect_uri", callbackURL)
q.Add("state", state)
if prompt != "" {
q.Add("prompt", prompt)
}
if connectionName != "" {
q.Add("connection", connectionName)
}
if audience != "" {
q.Add("audience", audience)
}
if len(scopes) > 0 {
q.Add("scope", strings.Join(scopes, " "))
}
u := &url.URL{
Scheme: "https",
Host: domain,
Path: "/authorize",
RawQuery: q.Encode(),
}
return u.String(), nil
}