CreateApp returns an http.HandlerFunc that handles POST /oauth2-provider/apps
(db database.Store, accessURL *url.URL, auditor *audit.Auditor, logger slog.Logger)
| 69 | |
| 70 | // CreateApp returns an http.HandlerFunc that handles POST /oauth2-provider/apps |
| 71 | func 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} |
| 128 | func UpdateApp(db database.Store, accessURL *url.URL, auditor *audit.Auditor, logger slog.Logger) http.HandlerFunc { |
no test coverage detected