summaryrefslogtreecommitdiffstats
path: root/routers/user
diff options
context:
space:
mode:
authorJonas Franz <info@jonasfranz.software>2019-03-09 17:29:58 +0100
committerGitHub <noreply@github.com>2019-03-09 17:29:58 +0100
commit8fffb0616866cfe7a293b457d8703724666374cb (patch)
tree08e286ed4aeff36079b81eac5e58be4e5e789720 /routers/user
parent8211e01d9e6f283077c5692b62d7ea81e0a60f9e (diff)
downloadgitea-8fffb0616866cfe7a293b457d8703724666374cb.tar.gz
gitea-8fffb0616866cfe7a293b457d8703724666374cb.zip
Add regenerate secret feature for oauth2 (#6291)
* Add regenerate secret functionality * Fix lint
Diffstat (limited to 'routers/user')
-rw-r--r--routers/user/setting/oauth2.go28
1 files changed, 28 insertions, 0 deletions
diff --git a/routers/user/setting/oauth2.go b/routers/user/setting/oauth2.go
index 7ae8e7b7f6..1068b5db49 100644
--- a/routers/user/setting/oauth2.go
+++ b/routers/user/setting/oauth2.go
@@ -78,6 +78,34 @@ func OAuthApplicationsEdit(ctx *context.Context, form auth.EditOAuth2Application
ctx.HTML(200, tplSettingsOAuthApplications)
}
+// OAuthApplicationsRegenerateSecret handles the post request for regenerating the secret
+func OAuthApplicationsRegenerateSecret(ctx *context.Context) {
+ ctx.Data["Title"] = ctx.Tr("settings")
+ ctx.Data["PageIsSettingsApplications"] = true
+
+ app, err := models.GetOAuth2ApplicationByID(ctx.ParamsInt64("id"))
+ if err != nil {
+ if models.IsErrOAuthApplicationNotFound(err) {
+ ctx.NotFound("Application not found", err)
+ return
+ }
+ ctx.ServerError("GetOAuth2ApplicationByID", err)
+ return
+ }
+ if app.UID != ctx.User.ID {
+ ctx.NotFound("Application not found", nil)
+ return
+ }
+ ctx.Data["App"] = app
+ ctx.Data["ClientSecret"], err = app.GenerateClientSecret()
+ if err != nil {
+ ctx.ServerError("GenerateClientSecret", err)
+ return
+ }
+ ctx.Flash.Success(ctx.Tr("settings.update_oauth2_application_success"))
+ ctx.HTML(200, tplSettingsOAuthApplications)
+}
+
// OAuth2ApplicationShow displays the given application
func OAuth2ApplicationShow(ctx *context.Context) {
app, err := models.GetOAuth2ApplicationByID(ctx.ParamsInt64("id"))