Skip to content

Commit bea497f

Browse files
nextcloud oauth (#10562)
Fix #7078
1 parent 07f6ae3 commit bea497f

File tree

11 files changed

+396
-3
lines changed

11 files changed

+396
-3
lines changed

models/oauth2.go

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,15 +51,23 @@ var OAuth2Providers = map[string]OAuth2Provider{
5151
ProfileURL: oauth2.GetDefaultProfileURL("gitea"),
5252
},
5353
},
54+
"nextcloud": {Name: "nextcloud", DisplayName: "Nextcloud", Image: "/img/auth/nextcloud.png",
55+
CustomURLMapping: &oauth2.CustomURLMapping{
56+
TokenURL: oauth2.GetDefaultTokenURL("nextcloud"),
57+
AuthURL: oauth2.GetDefaultAuthURL("nextcloud"),
58+
ProfileURL: oauth2.GetDefaultProfileURL("nextcloud"),
59+
},
60+
},
5461
}
5562

5663
// OAuth2DefaultCustomURLMappings contains the map of default URL's for OAuth2 providers that are allowed to have custom urls
5764
// key is used to map the OAuth2Provider
5865
// value is the mapping as defined for the OAuth2Provider
5966
var OAuth2DefaultCustomURLMappings = map[string]*oauth2.CustomURLMapping{
60-
"github": OAuth2Providers["github"].CustomURLMapping,
61-
"gitlab": OAuth2Providers["gitlab"].CustomURLMapping,
62-
"gitea": OAuth2Providers["gitea"].CustomURLMapping,
67+
"github": OAuth2Providers["github"].CustomURLMapping,
68+
"gitlab": OAuth2Providers["gitlab"].CustomURLMapping,
69+
"gitea": OAuth2Providers["gitea"].CustomURLMapping,
70+
"nextcloud": OAuth2Providers["nextcloud"].CustomURLMapping,
6371
}
6472

6573
// GetActiveOAuth2ProviderLoginSources returns all actived LoginOAuth2 sources

modules/auth/oauth2/oauth2.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import (
2222
"github.com/markbates/goth/providers/github"
2323
"github.com/markbates/goth/providers/gitlab"
2424
"github.com/markbates/goth/providers/google"
25+
"github.com/markbates/goth/providers/nextcloud"
2526
"github.com/markbates/goth/providers/openidConnect"
2627
"github.com/markbates/goth/providers/twitter"
2728
"github.com/satori/go.uuid"
@@ -192,6 +193,22 @@ func createProvider(providerName, providerType, clientID, clientSecret, openIDCo
192193
}
193194
}
194195
provider = gitea.NewCustomisedURL(clientID, clientSecret, callbackURL, authURL, tokenURL, profileURL)
196+
case "nextcloud":
197+
authURL := nextcloud.AuthURL
198+
tokenURL := nextcloud.TokenURL
199+
profileURL := nextcloud.ProfileURL
200+
if customURLMapping != nil {
201+
if len(customURLMapping.AuthURL) > 0 {
202+
authURL = customURLMapping.AuthURL
203+
}
204+
if len(customURLMapping.TokenURL) > 0 {
205+
tokenURL = customURLMapping.TokenURL
206+
}
207+
if len(customURLMapping.ProfileURL) > 0 {
208+
profileURL = customURLMapping.ProfileURL
209+
}
210+
}
211+
provider = nextcloud.NewCustomisedURL(clientID, clientSecret, callbackURL, authURL, tokenURL, profileURL)
195212
}
196213

197214
// always set the name if provider is created so we can support multiple setups of 1 provider
@@ -211,6 +228,8 @@ func GetDefaultTokenURL(provider string) string {
211228
return gitlab.TokenURL
212229
case "gitea":
213230
return gitea.TokenURL
231+
case "nextcloud":
232+
return nextcloud.TokenURL
214233
}
215234
return ""
216235
}
@@ -224,6 +243,8 @@ func GetDefaultAuthURL(provider string) string {
224243
return gitlab.AuthURL
225244
case "gitea":
226245
return gitea.AuthURL
246+
case "nextcloud":
247+
return nextcloud.AuthURL
227248
}
228249
return ""
229250
}
@@ -237,6 +258,8 @@ func GetDefaultProfileURL(provider string) string {
237258
return gitlab.ProfileURL
238259
case "gitea":
239260
return gitea.ProfileURL
261+
case "nextcloud":
262+
return nextcloud.ProfileURL
240263
}
241264
return ""
242265
}

options/locale/locale_en-US.ini

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1927,6 +1927,7 @@ auths.tips.oauth2.general = OAuth2 Authentication
19271927
auths.tips.oauth2.general.tip = When registering a new OAuth2 authentication, the callback/redirect URL should be: <host>/user/oauth2/<Authentication Name>/callback
19281928
auths.tip.oauth2_provider = OAuth2 Provider
19291929
auths.tip.bitbucket = Register a new OAuth consumer on https://bitbucket.org/account/user/<your username>/oauth-consumers/new and add the permission 'Account' - 'Read'
1930+
auths.tip.nextcloud = Register a new OAuth consumer on your instance using the following menu "Settings -> Security -> OAuth 2.0 client"
19301931
auths.tip.dropbox = Create a new application at https://www.dropbox.com/developers/apps
19311932
auths.tip.facebook = Register a new application at https://developers.facebook.com/apps and add the product "Facebook Login"
19321933
auths.tip.github = Register a new OAuth application on https://github.com/settings/applications/new

public/img/auth/nextcloud.png

2.85 KB
Loading

templates/admin/auth/new.tmpl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,8 @@
115115
<span>{{.i18n.Tr "admin.auths.tip.discord"}}</span>
116116
<li>Gitea</li>
117117
<span>{{.i18n.Tr "admin.auths.tip.gitea"}}</span>
118+
<li>Nextcloud</li>
119+
<span>{{.i18n.Tr "admin.auths.tip.nextcloud"}}</span>
118120
</div>
119121
</div>
120122
</div>

vendor/github.com/markbates/goth/providers/nextcloud/README.md

Lines changed: 85 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/markbates/goth/providers/nextcloud/nextcloud.go

Lines changed: 208 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Loading

0 commit comments

Comments
 (0)