mirror of
https://github.com/writefreely/writefreely
synced 2024-11-10 11:24:13 +00:00
simplify gitlab oauth config
This commit is contained in:
parent
c292512b9d
commit
26b6ed5f4f
5 changed files with 11 additions and 10 deletions
|
@ -309,6 +309,7 @@ func viewLogin(app *App, w http.ResponseWriter, r *http.Request) error {
|
|||
OauthSlack bool
|
||||
OauthWriteAs bool
|
||||
OauthGitlab bool
|
||||
GitlabHost string
|
||||
}{
|
||||
pageForReq(app, r),
|
||||
r.FormValue("to"),
|
||||
|
@ -318,6 +319,7 @@ func viewLogin(app *App, w http.ResponseWriter, r *http.Request) error {
|
|||
app.Config().SlackOauth.ClientID != "",
|
||||
app.Config().WriteAsOauth.ClientID != "",
|
||||
app.Config().GitlabOauth.ClientID != "",
|
||||
config.OrDefaultString(app.Config().GitlabOauth.DisplayName, gitlabDisplayName),
|
||||
}
|
||||
|
||||
if earlyError != "" {
|
||||
|
|
|
@ -72,9 +72,8 @@ type (
|
|||
GitlabOauthCfg struct {
|
||||
ClientID string `ini:"client_id"`
|
||||
ClientSecret string `ini:"client_secret"`
|
||||
AuthLocation string `ini:"auth_location"`
|
||||
TokenLocation string `ini:"token_location"`
|
||||
InspectLocation string `ini:"inspect_location"`
|
||||
Host string `ini:"host"`
|
||||
DisplayName string `ini:"display_name"`
|
||||
CallbackProxy string `ini:"callback_proxy"`
|
||||
CallbackProxyAPI string `ini:"callback_proxy_api"`
|
||||
}
|
||||
|
|
7
oauth.go
7
oauth.go
|
@ -179,12 +179,13 @@ func configureGitlabOauth(parentHandler *Handler, r *mux.Router, app *App) {
|
|||
callbackLocation = app.Config().GitlabOauth.CallbackProxy
|
||||
}
|
||||
|
||||
address := config.OrDefaultString(app.Config().GitlabOauth.Host, gitlabHost)
|
||||
oauthClient := gitlabOauthClient{
|
||||
ClientID: app.Config().GitlabOauth.ClientID,
|
||||
ClientSecret: app.Config().GitlabOauth.ClientSecret,
|
||||
ExchangeLocation: config.OrDefaultString(app.Config().GitlabOauth.TokenLocation, gitlabExchangeLocation),
|
||||
InspectLocation: config.OrDefaultString(app.Config().GitlabOauth.InspectLocation, gitlabIdentityLocation),
|
||||
AuthLocation: config.OrDefaultString(app.Config().GitlabOauth.AuthLocation, gitlabAuthLocation),
|
||||
ExchangeLocation: address + "/oauth/token",
|
||||
InspectLocation: address + "/api/v4/user",
|
||||
AuthLocation: address + "/oauth/authorize",
|
||||
HttpClient: config.DefaultHTTPClient(),
|
||||
CallbackLocation: callbackLocation,
|
||||
}
|
||||
|
|
|
@ -21,9 +21,8 @@ type gitlabOauthClient struct {
|
|||
var _ oauthClient = gitlabOauthClient{}
|
||||
|
||||
const (
|
||||
gitlabAuthLocation = "https://gitlab.com/oauth/authorize"
|
||||
gitlabExchangeLocation = "https://gitlab.com/oauth/token"
|
||||
gitlabIdentityLocation = "https://gitlab.com/api/v4/user"
|
||||
gitlabHost = "https://gitlab.com"
|
||||
gitlabDisplayName = "GitLab"
|
||||
)
|
||||
|
||||
func (c gitlabOauthClient) GetProvider() string {
|
||||
|
|
|
@ -55,7 +55,7 @@ hr.short {
|
|||
<a class="btn cta loginbtn" id="writeas-login" href="/oauth/write.as">Sign in with <strong>Write.as</strong></a>
|
||||
{{ end }}
|
||||
{{ if .OauthGitlab }}
|
||||
<a class="btn cta loginbtn" id="gitlab-login" href="/oauth/gitlab">Sign in with <strong>GitLab</strong></a>
|
||||
<a class="btn cta loginbtn" id="gitlab-login" href="/oauth/gitlab">Sign in with <strong>{{ .GitlabDisplayName }}</strong></a>
|
||||
{{ end }}
|
||||
</div>
|
||||
|
||||
|
|
Loading…
Reference in a new issue