Skip to content

Commit 8e9f5e1

Browse files
committed
fix
1 parent 4c290e9 commit 8e9f5e1

File tree

3 files changed

+35
-3
lines changed

3 files changed

+35
-3
lines changed

routers/web/auth/oauth.go

+19-3
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,15 @@
44
package auth
55

66
import (
7-
stdContext "context"
7+
go_context "context"
88
"encoding/base64"
99
"errors"
1010
"fmt"
1111
"html"
1212
"io"
1313
"net/http"
1414
"net/url"
15+
"sort"
1516
"strings"
1617

1718
"code.gitea.io/gitea/models/auth"
@@ -39,6 +40,7 @@ import (
3940
"github.com/golang-jwt/jwt/v4"
4041
"github.com/markbates/goth"
4142
"github.com/markbates/goth/gothic"
43+
go_oauth2 "golang.org/x/oauth2"
4244
)
4345

4446
const (
@@ -143,7 +145,7 @@ type AccessTokenResponse struct {
143145
IDToken string `json:"id_token,omitempty"`
144146
}
145147

146-
func newAccessTokenResponse(ctx stdContext.Context, grant *auth.OAuth2Grant, serverKey, clientKey oauth2.JWTSigningKey) (*AccessTokenResponse, *AccessTokenError) {
148+
func newAccessTokenResponse(ctx go_context.Context, grant *auth.OAuth2Grant, serverKey, clientKey oauth2.JWTSigningKey) (*AccessTokenResponse, *AccessTokenError) {
147149
if setting.OAuth2.InvalidateRefreshTokens {
148150
if err := grant.IncreaseCounter(ctx); err != nil {
149151
return nil, &AccessTokenError{
@@ -886,6 +888,17 @@ func SignInOAuth(ctx *context.Context) {
886888
func SignInOAuthCallback(ctx *context.Context) {
887889
provider := ctx.Params(":provider")
888890

891+
if ctx.Req.FormValue("error") != "" {
892+
var errorKeyValues []string
893+
for k, vv := range ctx.Req.Form {
894+
for _, v := range vv {
895+
errorKeyValues = append(errorKeyValues, fmt.Sprintf("%s = %s", html.EscapeString(k), html.EscapeString(v)))
896+
}
897+
}
898+
sort.Strings(errorKeyValues)
899+
ctx.Flash.Error(strings.Join(errorKeyValues, "<br>"), true)
900+
}
901+
889902
// first look if the provider is still active
890903
authSource, err := auth.GetActiveOAuth2SourceByName(provider)
891904
if err != nil {
@@ -894,7 +907,7 @@ func SignInOAuthCallback(ctx *context.Context) {
894907
}
895908

896909
if authSource == nil {
897-
ctx.ServerError("SignIn", errors.New("No valid provider found, check configured callback url in provider"))
910+
ctx.ServerError("SignIn", errors.New("no valid provider found, check configured callback url in provider"))
898911
return
899912
}
900913

@@ -920,6 +933,9 @@ func SignInOAuthCallback(ctx *context.Context) {
920933
ctx.Redirect(setting.AppSubURL + "/user/login")
921934
return
922935
}
936+
if err, ok := err.(*go_oauth2.RetrieveError); ok {
937+
ctx.Flash.Error("OAuth2 RetrieveError: "+err.Error(), true)
938+
}
923939
ctx.ServerError("UserSignIn", err)
924940
return
925941
}

templates/admin/auth/edit.tmpl

+11
Original file line numberDiff line numberDiff line change
@@ -434,6 +434,17 @@
434434
</div>
435435
</form>
436436
</div>
437+
438+
<h4 class="ui top attached header">
439+
{{.locale.Tr "admin.auths.tips"}}
440+
</h4>
441+
<div class="ui attached segment">
442+
<h5>GMail Settings:</h5>
443+
<p>Host: smtp.gmail.com, Port: 587, Enable TLS Encryption: true</p>
444+
445+
<h5>{{.locale.Tr "admin.auths.tips.oauth2.general"}}:</h5>
446+
<p>{{.locale.Tr "admin.auths.tips.oauth2.general.tip"}}</p>
447+
</div>
437448
</div>
438449

439450
<div class="ui g-modal-confirm delete modal">

templates/status/500.tmpl

+5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
{{/* This page should only depend the minimal template functions/variables, to avoid triggering new panics.
22
* base template functions: AppName, AssetUrlPrefix, AssetVersion, AppSubUrl, DefaultTheme, Str2html
33
* locale
4+
* Flash
45
* ErrorMsg
56
* SignedUser (optional)
67
*/}}
@@ -28,6 +29,10 @@
2829
</div>
2930
</nav>
3031
<div role="main" class="page-content status-page-500">
32+
<div class="ui container" >
33+
<style> .ui.message.flash-message { text-align: left; } </style>
34+
{{template "base/alert" .}}
35+
</div>
3136
<p class="gt-mt-5 center"><img src="{{AssetUrlPrefix}}/img/500.png" alt="Internal Server Error"></p>
3237
<div class="ui divider"></div>
3338
<div class="ui container gt-my-5">

0 commit comments

Comments
 (0)