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
54 changes: 54 additions & 0 deletions go.sum

Large diffs are not rendered by default.

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
9 changes: 9 additions & 0 deletions modules/auth/oauth2/oauth2.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"github.com/markbates/goth/providers/github"
"github.com/markbates/goth/providers/gitlab"
"github.com/markbates/goth/providers/google"
"github.com/markbates/goth/providers/mastodon"
"github.com/markbates/goth/providers/nextcloud"
"github.com/markbates/goth/providers/openidConnect"
"github.com/markbates/goth/providers/twitter"
Expand Down Expand Up @@ -213,6 +214,12 @@ func createProvider(providerName, providerType, clientID, clientSecret, openIDCo
case "yandex":
// 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":
instanceURL := mastodon.InstanceURL
if customURLMapping != nil && 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 @@ -249,6 +256,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>
185 changes: 185 additions & 0 deletions vendor/github.com/markbates/goth/providers/mastodon/mastodon.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

63 changes: 63 additions & 0 deletions vendor/github.com/markbates/goth/providers/mastodon/session.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions vendor/modules.txt
Original file line number Diff line number Diff line change
Expand Up @@ -559,6 +559,7 @@ github.com/markbates/goth/providers/gitea
github.com/markbates/goth/providers/github
github.com/markbates/goth/providers/gitlab
github.com/markbates/goth/providers/google
github.com/markbates/goth/providers/mastodon
github.com/markbates/goth/providers/nextcloud
github.com/markbates/goth/providers/openidConnect
github.com/markbates/goth/providers/twitter
Expand Down
5 changes: 5 additions & 0 deletions web_src/js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -1798,6 +1798,7 @@ function initAdmin() {
case 'gitlab':
case 'gitea':
case 'nextcloud':
case 'mastodon':
$('.oauth2_use_custom_url').show();
break;
case 'openidConnect':
Expand Down Expand Up @@ -1831,6 +1832,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();
break;
}
}
}
Expand Down