Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#12897 - add mastodon provider #13293

Merged
merged 11 commits into from
Oct 25, 2020
6 changes: 6 additions & 0 deletions models/oauth2.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,11 @@ var OAuth2Providers = map[string]OAuth2Provider{
},
},
"yandex": {Name: "yandex", DisplayName: "Yandex", Image: "/img/auth/yandex.png"},
"mastodon": {Name: "mastodon", DisplayName: "Mastodon", Image: "/img/auth/mastodon.png",
CustomURLMapping: &oauth2.CustomURLMapping{
AuthURL: oauth2.GetDefaultAuthURL("mastodon"),
},
},
}

// OAuth2DefaultCustomURLMappings contains the map of default URL's for OAuth2 providers that are allowed to have custom urls
Expand All @@ -69,6 +74,7 @@ var OAuth2DefaultCustomURLMappings = map[string]*oauth2.CustomURLMapping{
"gitlab": OAuth2Providers["gitlab"].CustomURLMapping,
"gitea": OAuth2Providers["gitea"].CustomURLMapping,
"nextcloud": OAuth2Providers["nextcloud"].CustomURLMapping,
"mastodon": OAuth2Providers["mastodon"].CustomURLMapping,
}

// GetActiveOAuth2ProviderLoginSources returns all actived LoginOAuth2 sources
Expand Down
10 changes: 9 additions & 1 deletion modules/auth/oauth2/oauth2.go
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,13 @@ func createProvider(providerName, providerType, clientID, clientSecret, openIDCo
// See https://tech.yandex.com/passport/doc/dg/reference/response-docpage/
provider = yandex.New(clientID, clientSecret, callbackURL, "login:email", "login:info", "login:avatar")
case "mastodon":
provider = mastodon.New(clientID, clientSecret, callbackURL)
instanceURL := mastodon.InstanceURL
if customURLMapping != nil {
techknowlogick marked this conversation as resolved.
Show resolved Hide resolved
if len(customURLMapping.AuthURL) > 0 {
instanceURL = customURLMapping.AuthURL
}
}
provider = mastodon.NewCustomisedURL(clientID, clientSecret, callbackURL, instanceURL)
}

// always set the name if provider is created so we can support multiple setups of 1 provider
Expand Down Expand Up @@ -252,6 +258,8 @@ func GetDefaultAuthURL(provider string) string {
return gitea.AuthURL
case "nextcloud":
return nextcloud.AuthURL
case "mastodon":
return mastodon.InstanceURL
}
return ""
}
Expand Down
1 change: 1 addition & 0 deletions options/locale/locale_en-US.ini
Original file line number Diff line number Diff line change
Expand Up @@ -2208,6 +2208,7 @@ auths.tip.twitter = Go to https://dev.twitter.com/apps, create an application an
auths.tip.discord = Register a new application on https://discordapp.com/developers/applications/me
auths.tip.gitea = Register a new OAuth2 application. Guide can be found at https://docs.gitea.io/en-us/oauth2-provider/
auths.tip.yandex = Create a new application at https://oauth.yandex.com/client/new. Select following permissions from the "Yandex.Passport API" section: "Access to email address", "Access to user avatar" and "Access to username, first name and surname, gender"
auths.tip.mastodon = Input a custom instance URL for the mastodon instance you want to authenticate with (or use the default one)
auths.edit = Edit Authentication Source
auths.activated = This Authentication Source is Activated
auths.new_success = The authentication '%s' has been added.
Expand Down
Binary file added public/img/auth/mastodon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions templates/admin/auth/new.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,8 @@
<span>{{.i18n.Tr "admin.auths.tip.nextcloud"}}</span>
<li>Yandex</li>
<span>{{.i18n.Tr "admin.auths.tip.yandex"}}</span>
<li>Mastodon</li>
<span>{{.i18n.Tr "admin.auths.tip.mastodon"}}</span>
</div>
</div>
</div>
Expand Down
2 changes: 1 addition & 1 deletion templates/admin/auth/source/oauth.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,4 @@
<input id="{{$key}}_email_url" value="{{$value.EmailURL}}" type="hidden" />
{{end}}
{{end}}
</div>
</div>
5 changes: 5 additions & 0 deletions web_src/js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -1797,6 +1797,7 @@ function initAdmin() {
case 'gitlab':
case 'gitea':
case 'nextcloud':
case 'mastodon':
$('.oauth2_use_custom_url').show();
break;
case 'openidConnect':
Expand Down Expand Up @@ -1830,6 +1831,10 @@ function initAdmin() {
$('.oauth2_token_url, .oauth2_auth_url, .oauth2_profile_url').show();
$('#oauth2_email_url').val('');
break;
case 'mastodon':
$('.oauth2_auth_url input').attr('required', 'required');
$('.oauth2_auth_url').show()
lafriks marked this conversation as resolved.
Show resolved Hide resolved
break;
}
}
}
Expand Down