af61b2249a
* add API endpoint to create OAuth2 Application. * move endpoint to /user. Add swagger documentations and proper response type. * change json tags to snake_case. add CreateOAuth2ApplicationOptions to swagger docs. * change response status to Created (201) * add methods to list OAuth2 apps and delete an existing OAuth2 app by ID. * add APIFormat convert method and file header * fixed header * hide secret on oauth2 application list * add Created time to API response * add API integration tests for create/list/delete OAuth2 applications. Co-authored-by: techknowlogick <matti@mdranta.net> Co-authored-by: zeripath <art27@cantab.net> Co-authored-by: guillep2k <18600385+guillep2k@users.noreply.github.com>
56 lines
1.8 KiB
Go
56 lines
1.8 KiB
Go
// Copyright 2014 The Gogs Authors. All rights reserved.
|
|
// Copyright 2019 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 structs
|
|
|
|
import (
|
|
"encoding/base64"
|
|
"time"
|
|
)
|
|
|
|
// BasicAuthEncode generate base64 of basic auth head
|
|
func BasicAuthEncode(user, pass string) string {
|
|
return base64.StdEncoding.EncodeToString([]byte(user + ":" + pass))
|
|
}
|
|
|
|
// AccessToken represents an API access token.
|
|
// swagger:response AccessToken
|
|
type AccessToken struct {
|
|
ID int64 `json:"id"`
|
|
Name string `json:"name"`
|
|
Token string `json:"sha1"`
|
|
TokenLastEight string `json:"token_last_eight"`
|
|
}
|
|
|
|
// AccessTokenList represents a list of API access token.
|
|
// swagger:response AccessTokenList
|
|
type AccessTokenList []*AccessToken
|
|
|
|
// CreateAccessTokenOption options when create access token
|
|
// swagger:parameters userCreateToken
|
|
type CreateAccessTokenOption struct {
|
|
Name string `json:"name" binding:"Required"`
|
|
}
|
|
|
|
// CreateOAuth2ApplicationOptions holds options to create an oauth2 application
|
|
type CreateOAuth2ApplicationOptions struct {
|
|
Name string `json:"name" binding:"Required"`
|
|
RedirectURIs []string `json:"redirect_uris" binding:"Required"`
|
|
}
|
|
|
|
// OAuth2Application represents an OAuth2 application.
|
|
// swagger:response OAuth2Application
|
|
type OAuth2Application struct {
|
|
ID int64 `json:"id"`
|
|
Name string `json:"name"`
|
|
ClientID string `json:"client_id"`
|
|
ClientSecret string `json:"client_secret"`
|
|
RedirectURIs []string `json:"redirect_uris"`
|
|
Created time.Time `json:"created"`
|
|
}
|
|
|
|
// OAuth2ApplicationList represents a list of OAuth2 applications.
|
|
// swagger:response OAuth2ApplicationList
|
|
type OAuth2ApplicationList []*OAuth2Application
|