-
Notifications
You must be signed in to change notification settings - Fork 3
/
jwks.go
30 lines (24 loc) · 956 Bytes
/
jwks.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
package api
import (
"context"
"net/http"
"github.com/ONSdigital/dp-identity-api/models"
)
// CognitoPoolJWKSHandler handles the retrieval of pool specific web key set
func (api *API) CognitoPoolJWKSHandler(ctx context.Context, w http.ResponseWriter, req *http.Request) (*models.SuccessResponse, *models.ErrorResponse) {
keyData, err := api.JWKSHandler.JWKSGetKeyset(api.AWSRegion, api.UserPoolId)
if err != nil {
return nil, models.NewErrorResponse(http.StatusNotFound, nil, err)
}
jsonResponse, err := api.JWKSHandler.JWKSToRSAJSONResponse(keyData)
if err != nil {
return nil, handleJWKSParsingErrors(ctx, err)
}
return models.NewSuccessResponse(jsonResponse, http.StatusOK, nil), nil
}
func handleJWKSParsingErrors(ctx context.Context, err error) *models.ErrorResponse {
return models.NewErrorResponse(http.StatusInternalServerError,
nil,
models.NewError(ctx, err, models.JWKSParseError, models.JWKSParseErrorDescription),
)
}