OAuth

/app/lib/auth/available.go (3.7 KB)

  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
117
118
119
120
121
122
123
124
125
126
127
package auth

import (
"fmt"
"slices"

"github.com/samber/lo"

"{{{ .Package }}}/app/util"
)

var (
AvailableProviderNames map[string]string
AvailableProviderKeys []string
)

const (
auth0Key = "auth0"
microsoftKey = "microsoft"
nextcloudKey = "nextcloud"
OpenIDConnectKey = "openid_connect"
wecomKey = "wecom"
)

func initAvailable() {
if AvailableProviderNames == nil {
openIDConnectName := util.GetEnv(OpenIDConnectKey + "_name")
if openIDConnectName == "" {
openIDConnectName = "OpenID Connect"
}
AvailableProviderNames = map[string]string{
"amazon": "Amazon",
"apple": "Apple",
auth0Key: "Auth0",
"azuread": "Azure AD",
"battlenet": "Battlenet",
"bitbucket": "Bitbucket",
"bitly": "Bitly",
"box": "Box",
"cloudfoundry": "Cloud Foundry",
"cognito": "Cognito",
"dailymotion": "Dailymotion",
"deezer": "Deezer",
"digitalocean": "Digital Ocean",
"discord": "Discord",
"dropbox": "Dropbox",
"eveonline": "Eve Online",
"facebook": "Facebook",
"fitbit": "Fitbit",
"gitea": "Gitea",
"github": "Github",
"gitlab": "Gitlab",
"google": "Google",
"gplus": "Google Plus",
"heroku": "Heroku",
"influxcloud": "InfluxCloud",
"instagram": "Instagram",
"intercom": "Intercom",
"kakao": "Kakao",
"lastfm": "Last FM",
"line": "LINE",
"linkedin": "Linkedin",
"mailru": "Mailru",
"mastodon": "Mastodon",
"meetup": "Meetup.com",
microsoftKey: "Microsoft",
"microsoftonline": "Microsoft Online",
"naver": "Naver",
nextcloudKey: "NextCloud",
"okta": "Okta",
"onedrive": "Onedrive",
OpenIDConnectKey: openIDConnectName,
"oura": "Oura",
"patreon": "Patreon",
"paypal": "Paypal",
"salesforce": "Salesforce",
"seatalk": "SeaTalk",
"shopify": "Shopify",
"slack": "Slack",
"soundcloud": "SoundCloud",
"spotify": "Spotify",
"steam": "Steam",
"strava": "Strava",
"stripe": "Stripe",
"tiktok": "TikTok",
"tumblr": "Tumblr",
"twitch": "Twitch",
"twitter": "Twitter",
"typetalk": "Typetalk",
"uber": "Uber",
"vk": "VK",
"wecom": "WeCom",
"wepay": "Wepay",
"xero": "Xero",
"yahoo": "Yahoo",
"yammer": "Yammer",
"yandex": "Yandex",
"zoom": "Zoom",
}
AvailableProviderKeys = lo.Keys(AvailableProviderNames)
slices.Sort(AvailableProviderKeys)
}
}

func ProviderUsage(id string, enabled bool) string {
n, ok := AvailableProviderNames[id]
if !ok {
return "INVALID PROVIDER [" + id + "]"
}
if enabled {
return n + " is already configured"
}
keys := []string{fmt.Sprintf(`"%s_key"`, id), fmt.Sprintf(`"%s_secret"`, id), fmt.Sprintf(`"%s_scopes"`, id)}
switch id {
case auth0Key:
keys = append(keys, "\"auth0_domain\"")
case microsoftKey:
keys = append(keys, "\"microsoft_tenant\"")
case nextcloudKey:
keys = append(keys, "\"nextcloud_url\"")
case OpenIDConnectKey:
keys = append(keys, "\"openid_connect_url\"", "\"openid_connect_name\"")
case wecomKey:
keys = append(keys, "\"wecom_agent_id\"")
}
return fmt.Sprintf("To enable %s, set %s as environment variables", n, util.StringArrayOxfordComma(keys, "and"))
}