ShowAuthorizePage handles GET /oauth2/authorize requests to display the HTML authorization page.
(accessURL *url.URL)
| 85 | |
| 86 | // ShowAuthorizePage handles GET /oauth2/authorize requests to display the HTML authorization page. |
| 87 | func ShowAuthorizePage(accessURL *url.URL) http.HandlerFunc { |
| 88 | return func(rw http.ResponseWriter, r *http.Request) { |
| 89 | app := httpmw.OAuth2ProviderApp(r) |
| 90 | ua := httpmw.UserAuthorization(r.Context()) |
| 91 | |
| 92 | callbackURL, err := url.Parse(app.CallbackURL) |
| 93 | if err != nil { |
| 94 | site.RenderStaticErrorPage(rw, r, site.ErrorPageData{ |
| 95 | Status: http.StatusInternalServerError, |
| 96 | HideStatus: false, |
| 97 | Title: "Internal Server Error", |
| 98 | Description: err.Error(), |
| 99 | Actions: []site.Action{ |
| 100 | { |
| 101 | URL: accessURL.String(), |
| 102 | Text: "Back to site", |
| 103 | }, |
| 104 | }, |
| 105 | }) |
| 106 | return |
| 107 | } |
| 108 | |
| 109 | params, validationErrs, err := extractAuthorizeParams(r, callbackURL) |
| 110 | if err != nil { |
| 111 | errStr := make([]string, len(validationErrs)) |
| 112 | for i, err := range validationErrs { |
| 113 | errStr[i] = err.Detail |
| 114 | } |
| 115 | site.RenderStaticErrorPage(rw, r, site.ErrorPageData{ |
| 116 | Status: http.StatusBadRequest, |
| 117 | HideStatus: false, |
| 118 | Title: "Invalid Query Parameters", |
| 119 | Description: "One or more query parameters are missing or invalid.", |
| 120 | Warnings: errStr, |
| 121 | Actions: []site.Action{ |
| 122 | { |
| 123 | URL: accessURL.String(), |
| 124 | Text: "Back to site", |
| 125 | }, |
| 126 | }, |
| 127 | }) |
| 128 | return |
| 129 | } |
| 130 | |
| 131 | if params.responseType != codersdk.OAuth2ProviderResponseTypeCode { |
| 132 | site.RenderStaticErrorPage(rw, r, site.ErrorPageData{ |
| 133 | Status: http.StatusBadRequest, |
| 134 | HideStatus: false, |
| 135 | Title: "Unsupported Response Type", |
| 136 | Description: "Only response_type=code is supported.", |
| 137 | Actions: []site.Action{ |
| 138 | { |
| 139 | URL: accessURL.String(), |
| 140 | Text: "Back to site", |
| 141 | }, |
| 142 | }, |
| 143 | }) |
| 144 | return |
no test coverage detected