MCPcopy Index your code
hub / github.com/coder/coder / CreateApp

Function CreateApp

coderd/oauth2provider/apps.go:71–125  ·  view source on GitHub ↗

CreateApp returns an http.HandlerFunc that handles POST /oauth2-provider/apps

(db database.Store, accessURL *url.URL, auditor *audit.Auditor, logger slog.Logger)

Source from the content-addressed store, hash-verified

69
70// CreateApp returns an http.HandlerFunc that handles POST /oauth2-provider/apps
71func CreateApp(db database.Store, accessURL *url.URL, auditor *audit.Auditor, logger slog.Logger) http.HandlerFunc {
72 return func(rw http.ResponseWriter, r *http.Request) {
73 var (
74 ctx = r.Context()
75 aReq, commitAudit = audit.InitRequest[database.OAuth2ProviderApp](rw, &audit.RequestParams{
76 Audit: *auditor,
77 Log: logger,
78 Request: r,
79 Action: database.AuditActionCreate,
80 })
81 )
82 defer commitAudit()
83 var req codersdk.PostOAuth2ProviderAppRequest
84 if !httpapi.Read(ctx, rw, r, &req) {
85 return
86 }
87 app, err := db.InsertOAuth2ProviderApp(ctx, database.InsertOAuth2ProviderAppParams{
88 ID: uuid.New(),
89 CreatedAt: dbtime.Now(),
90 UpdatedAt: dbtime.Now(),
91 Name: req.Name,
92 Icon: req.Icon,
93 CallbackURL: req.CallbackURL,
94 RedirectUris: []string{},
95 ClientType: sql.NullString{String: "confidential", Valid: true},
96 DynamicallyRegistered: sql.NullBool{Bool: false, Valid: true},
97 ClientIDIssuedAt: sql.NullTime{},
98 ClientSecretExpiresAt: sql.NullTime{},
99 GrantTypes: []string{"authorization_code", "refresh_token"},
100 ResponseTypes: []string{"code"},
101 TokenEndpointAuthMethod: sql.NullString{String: "client_secret_post", Valid: true},
102 Scope: sql.NullString{},
103 Contacts: []string{},
104 ClientUri: sql.NullString{},
105 LogoUri: sql.NullString{},
106 TosUri: sql.NullString{},
107 PolicyUri: sql.NullString{},
108 JwksUri: sql.NullString{},
109 Jwks: pqtype.NullRawMessage{},
110 SoftwareID: sql.NullString{},
111 SoftwareVersion: sql.NullString{},
112 RegistrationAccessToken: nil,
113 RegistrationClientUri: sql.NullString{},
114 })
115 if err != nil {
116 httpapi.Write(ctx, rw, http.StatusInternalServerError, codersdk.Response{
117 Message: "Internal error creating OAuth2 application.",
118 Detail: err.Error(),
119 })
120 return
121 }
122 aReq.New = app
123 httpapi.Write(ctx, rw, http.StatusCreated, db2sdk.OAuth2ProviderApp(accessURL, app))
124 }
125}
126
127// UpdateApp returns an http.HandlerFunc that handles PUT /oauth2-provider/apps/{app}
128func UpdateApp(db database.Store, accessURL *url.URL, auditor *audit.Auditor, logger slog.Logger) http.HandlerFunc {

Callers 1

postOAuth2ProviderAppMethod · 0.92

Calls 9

InitRequestFunction · 0.92
ReadFunction · 0.92
NowFunction · 0.92
WriteFunction · 0.92
OAuth2ProviderAppFunction · 0.92
ContextMethod · 0.65
NewMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected