@@ -153,6 +153,15 @@ func New(ctx context.Context, options *Options) (_ *API, err error) {
153
153
Optional :false ,
154
154
SessionTokenFunc :nil ,// Default behavior
155
155
})
156
+ // Same as above but it redirects to the login page.
157
+ apiKeyMiddlewareRedirect := httpmw .ExtractAPIKeyMW (httpmw.ExtractAPIKeyConfig {
158
+ DB :options .Database ,
159
+ OAuth2Configs :oauthConfigs ,
160
+ RedirectToLogin :true ,
161
+ DisableSessionExpiryRefresh :options .DeploymentValues .DisableSessionExpiryRefresh .Value (),
162
+ Optional :false ,
163
+ SessionTokenFunc :nil ,// Default behavior
164
+ })
156
165
apiKeyMiddlewareOptional := httpmw .ExtractAPIKeyMW (httpmw.ExtractAPIKeyConfig {
157
166
DB :options .Database ,
158
167
OAuth2Configs :oauthConfigs ,
@@ -168,25 +177,30 @@ func New(ctx context.Context, options *Options) (_ *API, err error) {
168
177
}
169
178
170
179
api .AGPL .RootHandler .Group (func (r chi.Router ) {
171
- //Oauth2 linking routes do not make sense under the /api/v2 path.
180
+ //OAuth2 linking routes do not make sense under the /api/v2 path.
172
181
r .Route ("/oauth2" ,func (r chi.Router ) {
173
182
r .Use (
174
183
api .oAuth2ProviderMiddleware ,
175
184
// Fetch the app as system because in the /tokens route there will be no
176
185
// authenticated user.
177
186
httpmw .AsAuthzSystem (httpmw .ExtractOAuth2ProviderApp (options .Database )),
178
187
)
179
- r .Group (func (r chi.Router ) {
180
- r .Use (apiKeyMiddleware )
181
- r .Get ("/authorize" ,api .postOAuth2ProviderAppAuthorize ())
182
- // DELETE on /tokens is not part of the OAuth2 spec. It is our own
183
- // route used to revoke permissions from an application. It is here for
184
- // parity with POST on /tokens.
185
- r .Delete ("/tokens" ,api .deleteOAuth2ProviderAppTokens ())
188
+ r .Route ("/authorize" ,func (r chi.Router ) {
189
+ r .Use (apiKeyMiddlewareRedirect )
190
+ r .Get ("/" ,api .getOAuth2ProviderAppAuthorize ())
191
+ })
192
+ r .Route ("/tokens" ,func (r chi.Router ) {
193
+ r .Group (func (r chi.Router ) {
194
+ r .Use (apiKeyMiddleware )
195
+ // DELETE on /tokens is not part of the OAuth2 spec. It is our own
196
+ // route used to revoke permissions from an application. It is here for
197
+ // parity with POST on /tokens.
198
+ r .Delete ("/" ,api .deleteOAuth2ProviderAppTokens ())
199
+ })
200
+ // The POST /tokens endpoint will be called from an unauthorized client so we
201
+ // cannot require an API key.
202
+ r .Post ("/" ,api .postOAuth2ProviderAppToken ())
186
203
})
187
- // The /tokens endpoint will be called from an unauthorized client so we
188
- // cannot require an API key.
189
- r .Post ("/tokens" ,api .postOAuth2ProviderAppToken ())
190
204
})
191
205
})
192
206