-
-
Notifications
You must be signed in to change notification settings - Fork 5.8k
Support instance-wide OAuth2 applications #21335
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
Merged
Merged
Changes from 7 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
99c86fc
Support instance-wide OAuth2 applications
qwerty287 93510e8
Merge branch 'main' into instance-oauth2
qwerty287 4972a16
fix indentation
qwerty287 6a3afda
fix indentation
qwerty287 88858db
Merge branch 'main' into instance-oauth2
qwerty287 ab1e62f
Reuse code
qwerty287 a85fd20
Merge branch 'main' into instance-oauth2
qwerty287 d5bf5d2
Update routers/web/admin/applications.go
wxiaoguang 3ffff0c
refactor route path
wxiaoguang a624c10
Merge branch 'main' into instance-oauth2
lafriks File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
// Copyright 2022 The Gitea Authors. All rights reserved. | ||
// Use of this source code is governed by a MIT-style | ||
// license that can be found in the LICENSE file.package admin | ||
|
||
package admin | ||
|
||
import ( | ||
"fmt" | ||
"net/http" | ||
|
||
"code.gitea.io/gitea/models/auth" | ||
"code.gitea.io/gitea/modules/base" | ||
"code.gitea.io/gitea/modules/context" | ||
"code.gitea.io/gitea/modules/setting" | ||
user_setting "code.gitea.io/gitea/routers/web/user/setting" | ||
) | ||
|
||
var ( | ||
// tplSettingsLabels template path for render application settings | ||
tplSettingsApplications base.TplName = "admin/applications/list" | ||
// tplSettingsLabels template path for render application edit settings | ||
tplSettingsEditApplication base.TplName = "admin/applications/edit" | ||
) | ||
|
||
func newOAuth2CommonHandlers() *user_setting.OAuth2CommonHandlers { | ||
return &user_setting.OAuth2CommonHandlers{ | ||
OwnerID: 0, | ||
BasePathList: fmt.Sprintf("%s/admin/applications", setting.AppSubURL), | ||
BasePathEditPrefix: fmt.Sprintf("%s/admin/applications", setting.AppSubURL), | ||
TplAppEdit: tplSettingsEditApplication, | ||
} | ||
} | ||
|
||
// Applications render org applications page (for org, at the moment, there are only OAuth2 applications) | ||
func Applications(ctx *context.Context) { | ||
ctx.Data["Title"] = ctx.Tr("settings.applications") | ||
ctx.Data["PageIsAdmin"] = true | ||
ctx.Data["PageIsAdminApplications"] = true | ||
|
||
apps, err := auth.GetOAuth2ApplicationsByUserID(ctx, 0) | ||
if err != nil { | ||
ctx.ServerError("GetOAuth2ApplicationsByUserID", err) | ||
return | ||
} | ||
ctx.Data["Applications"] = apps | ||
|
||
ctx.HTML(http.StatusOK, tplSettingsApplications) | ||
} | ||
|
||
// ApplicationsPost response for adding an oauth2 application | ||
func ApplicationsPost(ctx *context.Context) { | ||
ctx.Data["Title"] = ctx.Tr("settings.applications") | ||
ctx.Data["PageIsAdmin"] = true | ||
ctx.Data["PageIsAdminApplications"] = true | ||
|
||
oa := newOAuth2CommonHandlers() | ||
oa.AddApp(ctx) | ||
} | ||
|
||
// EditApplication displays the given application | ||
func EditApplication(ctx *context.Context) { | ||
ctx.Data["PageIsAdmin"] = true | ||
ctx.Data["PageIsAdminApplications"] = true | ||
|
||
oa := newOAuth2CommonHandlers() | ||
oa.EditShow(ctx) | ||
} | ||
|
||
// EditApplicationPost response for editing oauth2 application | ||
func EditApplicationPost(ctx *context.Context) { | ||
ctx.Data["Title"] = ctx.Tr("settings.applications") | ||
ctx.Data["PageIsAdmin"] = true | ||
ctx.Data["PageIsAdminApplications"] = true | ||
|
||
oa := newOAuth2CommonHandlers() | ||
oa.EditSave(ctx) | ||
} | ||
|
||
// ApplicationsRegenerateSecret handles the post request for regenerating the secret | ||
func ApplicationsRegenerateSecret(ctx *context.Context) { | ||
ctx.Data["Title"] = ctx.Tr("settings") | ||
ctx.Data["PageIsAdmin"] = true | ||
ctx.Data["PageIsAdminApplications"] = true | ||
|
||
oa := newOAuth2CommonHandlers() | ||
oa.RegenerateSecret(ctx) | ||
} | ||
|
||
// DeleteApplication deletes the given oauth2 application | ||
func DeleteApplication(ctx *context.Context) { | ||
oa := newOAuth2CommonHandlers() | ||
oa.DeleteApp(ctx) | ||
} | ||
|
||
// TODO: revokes the grant with the given id |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{{template "base/head" .}} | ||
<div class="page-content admin config"> | ||
{{template "admin/navbar" .}} | ||
|
||
{{template "user/settings/applications_oauth2_edit_form" .}} | ||
</div> | ||
{{template "base/footer" .}} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
{{template "base/head" .}} | ||
<div class="page-content admin config"> | ||
{{template "admin/navbar" .}} | ||
<div class="ui container"> | ||
<div class="twelve wide column content"> | ||
{{template "base/alert" .}} | ||
<h4 class="ui top attached header"> | ||
{{.locale.Tr "settings.applications"}} | ||
</h4> | ||
{{template "user/settings/applications_oauth2_list" .}} | ||
</div> | ||
</div> | ||
</div> | ||
{{template "base/footer" .}} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.