This repository has been archived by the owner on Apr 21, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
/
config.go
116 lines (107 loc) · 4.47 KB
/
config.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
package goconnect
/*
** Copyright 2017 Telenor Digital AS
**
** Licensed under the Apache License, Version 2.0 (the "License");
** you may not use this file except in compliance with the License.
** You may obtain a copy of the License at
**
** http://www.apache.org/licenses/LICENSE-2.0
**
** Unless required by applicable law or agreed to in writing, software
** distributed under the License is distributed on an "AS IS" BASIS,
** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
** See the License for the specific language governing permissions and
** limitations under the License.
*/
import "net/url"
const (
connectScheme = "https"
connectAuthPath = "/oauth/authorize"
connectJWKPath = "/oauth/public_keys.jwks"
connectTokenPath = "/oauth/token"
connectLogoutPath = "/oauth/logout"
)
const (
// DefaultHost is the Connect ID production host. We recommend using this.
DefaultHost = "connect.telenordigital.com"
// StagingHost is the host name for the staging (aka testing) environment
StagingHost = "connect.staging.telenordigital.com"
)
// These constants provide default values for ClientConfig.
const (
DefaultScopes = "openid profile email phone"
DefaultLoginInit = "login"
DefaultLogoutInit = "logout"
DefaultLoginRedirectURI = "http://localhost:8080/connect/oauth2callback"
DefaultLogoutRedirectURI = "http://localhost:8080/connect/logoutcallback"
DefaultLoginRedirect = "oauth2callback"
DefaultLogoutRedirect = "logoutcallback"
DefaultLoginCompleteRedirectURI = "/"
DefaultLogoutCompleteRedirectURI = "/"
DefaultProfileEndpoint = "profile"
)
// ClientConfig holds the ConnectID configuration.
type ClientConfig struct {
Host string // Host is the name of the Connect ID host to use.
Scopes string // Scopes is a space separated list of the OAuth scopes to use when logging in.
ClientID string // ClientID is the OAuth client ID.
Password string // Password is the (optional) secret.
LoginInit string // LoginInit is the endpoint for starting a login.
LogoutInit string // LogoutInit is the endpoint for starting a logout.
LoginRedirectURI string // LoginRedirectURI is where the OAuth server redirects after a successful login.
LogoutRedirectURI string // LogoutRedirectURI is where the OAuth server redirects after a successful logout.
LoginRedirect string // LoginRedirect is the endpoint that serves - and is thus typically a suffix of - LoginRedirectURI.
LogoutRedirect string // LogoutRedirect is the endpoint that serves - and is thus typically a suffix of - LogoutRedirectURI.
LoginCompleteRedirectURI string // LoginCompleteRedirectURI is where goconnect redirects after a successful login.
LogoutCompleteRedirectURI string // LogoutCompleteRedirectURI is where goconnect redirects after a successfull logout.
ProfileEndpoint string // ProfileEndpoint is the session profile information endpoint.
UseSecureCookie bool // UseSecureCookie indicates whether to use a secure cookie.
}
// NewDefaultConfig creates a configuration with default values prepopulated. If the
// parameter is set in the overrides parameter it won't be set.
func NewDefaultConfig(overrides ClientConfig) ClientConfig {
ret := overrides
if ret.Host == "" {
ret.Host = DefaultHost
}
if ret.Scopes == "" {
ret.Scopes = DefaultScopes
}
if ret.LoginInit == "" {
ret.LoginInit = DefaultLoginInit
}
if ret.LogoutInit == "" {
ret.LogoutInit = DefaultLogoutInit
}
if ret.LoginRedirectURI == "" {
ret.LoginRedirectURI = DefaultLoginRedirectURI
}
if ret.LogoutRedirectURI == "" {
ret.LogoutRedirectURI = DefaultLogoutRedirectURI
}
if ret.LoginRedirect == "" {
ret.LoginRedirect = DefaultLoginRedirect
}
if ret.LogoutRedirect == "" {
ret.LogoutRedirect = DefaultLogoutRedirect
}
if ret.LoginCompleteRedirectURI == "" {
ret.LoginCompleteRedirectURI = DefaultLoginCompleteRedirectURI
}
if ret.LogoutCompleteRedirectURI == "" {
ret.LogoutCompleteRedirectURI = DefaultLogoutCompleteRedirectURI
}
if ret.ProfileEndpoint == "" {
ret.ProfileEndpoint = DefaultProfileEndpoint
}
return ret
}
// Helper function to construct an URL for requests
func buildConnectURL(config ClientConfig, path string) url.URL {
return url.URL{
Scheme: connectScheme,
Host: config.Host,
Path: path,
}
}