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

Add API endpoints to manage OAuth2 Application (list/create/delete) #10437

Merged
merged 15 commits into from
Feb 29, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
add APIFormat convert method and file header
  • Loading branch information
Gustavo Marin committed Feb 25, 2020
commit 03554960f5449a7cf273a32a7762650c05d7aeeb
2 changes: 1 addition & 1 deletion models/oauth2_application.go
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ func ListOAuth2Applications(uid int64, listOptions ListOptions) ([]*OAuth2Applic
Where("uid=?", uid).
Desc("id")

if listOptions.Page == 0 {
if listOptions.Page != 0 {
sess = listOptions.setSessionPagination(sess)

apps := make([]*OAuth2Application, 0, listOptions.PageSize)
Expand Down
11 changes: 11 additions & 0 deletions modules/convert/convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -388,3 +388,14 @@ func ToTopicResponse(topic *models.Topic) *api.TopicResponse {
Updated: topic.UpdatedUnix.AsTime(),
}
}

// ToOAuth2Application convert from models.OAuth2Application to api.OAuth2Application
func ToOAuth2Application(app *models.OAuth2Application) *api.OAuth2Application {
return &api.OAuth2Application{
ID: app.ID,
Name: app.Name,
ClientID: app.ClientID,
ClientSecret: app.ClientSecret,
RedirectURIs: app.RedirectURIs,
}
}
5 changes: 5 additions & 0 deletions routers/api/v1/swagger/app.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
// Copyright 2014 The Gogs Authors. All rights reserved.
This conversation was marked as resolved.
Show resolved Hide resolved
// Copyright 2018 The Gitea Authors. All rights reserved.
This conversation was marked as resolved.
Show resolved Hide resolved
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.

package swagger
This conversation was marked as resolved.
Show resolved Hide resolved

import (
Expand Down
16 changes: 3 additions & 13 deletions routers/api/v1/user/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (

"code.gitea.io/gitea/models"
"code.gitea.io/gitea/modules/context"
"code.gitea.io/gitea/modules/convert"
api "code.gitea.io/gitea/modules/structs"
"code.gitea.io/gitea/routers/api/v1/utils"
)
Expand Down Expand Up @@ -168,13 +169,7 @@ func CreateOauth2Application(ctx *context.APIContext, data api.CreateOAuth2Appli
}
app.ClientSecret = secret

ctx.JSON(http.StatusCreated, api.OAuth2Application{
ID: app.ID,
Name: app.Name,
ClientID: app.ClientID,
ClientSecret: app.ClientSecret,
RedirectURIs: app.RedirectURIs,
})
ctx.JSON(http.StatusCreated, convert.ToOAuth2Application(app))
}

// ListOauth2Applications list all the Oauth2 application
Expand Down Expand Up @@ -205,12 +200,7 @@ func ListOauth2Applications(ctx *context.APIContext) {

apiApps := make([]*api.OAuth2Application, len(apps))
This conversation was marked as resolved.
Show resolved Hide resolved
for i := range apps {
apiApps[i] = &api.OAuth2Application{
ID: apps[i].ID,
Name: apps[i].Name,
ClientID: apps[i].ClientID,
RedirectURIs: apps[i].RedirectURIs,
}
apiApps[i] = convert.ToOAuth2Application(apps[i])
}
ctx.JSON(http.StatusOK, &apiApps)
}
Expand Down