/
oauth.go
113 lines (97 loc) · 3.25 KB
/
oauth.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
package oauth
import (
"net/http"
"github.com/iwarapter/pingaccess-sdk-go/v62/pingaccess"
"github.com/iwarapter/pingaccess-sdk-go/v62/pingaccess/client"
"github.com/iwarapter/pingaccess-sdk-go/v62/pingaccess/client/metadata"
"github.com/iwarapter/pingaccess-sdk-go/v62/pingaccess/config"
"github.com/iwarapter/pingaccess-sdk-go/v62/pingaccess/models"
"github.com/iwarapter/pingaccess-sdk-go/v62/pingaccess/request"
)
const (
// ServiceName - The name of service.
ServiceName = "Oauth"
)
//OauthService provides the API operations for making requests to
// Oauth endpoint.
type OauthService struct {
*client.Client
}
//New createa a new instance of the OauthService client.
//
// Example:
// cfg := config.NewConfig().WithUsername("Administrator").WithPassword("2Access").WithEndpoint(paURL)
//
// //Create a OauthService from the configuration
// svc := oauth.New(cfg)
//
func New(cfg *config.Config) *OauthService {
return &OauthService{Client: client.New(
*cfg,
metadata.ClientInfo{
ServiceName: ServiceName,
Endpoint: *cfg.Endpoint,
APIVersion: pingaccess.SDKVersion,
},
)}
}
// newRequest creates a new request for a Oauth operation
func (s *OauthService) newRequest(op *request.Operation, params, data interface{}) *request.Request {
req := s.NewRequest(op, params, data)
return req
}
//DeleteAuthorizationServerCommand - Resets the OpenID Connect Provider configuration to default values
//RequestType: DELETE
//Input:
func (s *OauthService) DeleteAuthorizationServerCommand() (resp *http.Response, err error) {
path := "/oauth/authServer"
op := &request.Operation{
Name: "DeleteAuthorizationServerCommand",
HTTPMethod: "DELETE",
HTTPPath: path,
}
req := s.newRequest(op, nil, nil)
if req.Send() == nil {
return req.HTTPResponse, nil
}
return req.HTTPResponse, req.Error
}
//GetAuthorizationServerCommand - Get Authorization Server configuration
//RequestType: GET
//Input:
func (s *OauthService) GetAuthorizationServerCommand() (output *models.AuthorizationServerView, resp *http.Response, err error) {
path := "/oauth/authServer"
op := &request.Operation{
Name: "GetAuthorizationServerCommand",
HTTPMethod: "GET",
HTTPPath: path,
}
output = &models.AuthorizationServerView{}
req := s.newRequest(op, nil, output)
if req.Send() == nil {
return output, req.HTTPResponse, nil
}
return nil, req.HTTPResponse, req.Error
}
//UpdateAuthorizationServerCommand - Update OAuth 2.0 Authorization Server configuration
//RequestType: PUT
//Input: input *UpdateAuthorizationServerCommandInput
func (s *OauthService) UpdateAuthorizationServerCommand(input *UpdateAuthorizationServerCommandInput) (output *models.AuthorizationServerView, resp *http.Response, err error) {
path := "/oauth/authServer"
op := &request.Operation{
Name: "UpdateAuthorizationServerCommand",
HTTPMethod: "PUT",
HTTPPath: path,
QueryParams: map[string]string{},
}
output = &models.AuthorizationServerView{}
req := s.newRequest(op, input.Body, output)
if req.Send() == nil {
return output, req.HTTPResponse, nil
}
return nil, req.HTTPResponse, req.Error
}
// UpdateAuthorizationServerCommandInput - Inputs for UpdateAuthorizationServerCommand
type UpdateAuthorizationServerCommandInput struct {
Body models.AuthorizationServerView
}