Skip to content

Commit

Permalink
jwksを返却するエンドポイントを作成
Browse files Browse the repository at this point in the history
  • Loading branch information
piny940 committed Nov 4, 2024
1 parent 7362b06 commit 3eec2eb
Show file tree
Hide file tree
Showing 10 changed files with 883 additions and 824 deletions.
1,573 changes: 793 additions & 780 deletions frontend/src/utils/api.d.ts

Large diffs are not rendered by default.

68 changes: 34 additions & 34 deletions internal/api/gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 14 additions & 1 deletion internal/api/oauth.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"auth/internal/domain/oauth"
"auth/internal/usecase"
"context"
"encoding/json"
"errors"
"net/url"
"strings"
Expand Down Expand Up @@ -174,5 +175,17 @@ func toDAuthParams(params OAuthInterfaceAuthorizeParams) *oauth.AuthRequest {
}

func (s *Server) OAuthInterfaceGetJwks(ctx context.Context, request OAuthInterfaceGetJwksRequestObject) (OAuthInterfaceGetJwksResponseObject, error) {
panic("unimplemented")
set, err := s.OAuthUsecase.GetJWKs()
if err != nil {
return nil, err
}
data, err := json.Marshal(set)
if err != nil {
return nil, err
}
res := make(map[string]interface{})
if err := json.Unmarshal(data, &res); err != nil {
return nil, err
}
return OAuthInterfaceGetJwks200JSONResponse(res), nil
}
21 changes: 21 additions & 0 deletions internal/api/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"errors"
"net/http"
"net/url"
"reflect"
"strings"

"github.com/gorilla/securecookie"
Expand Down Expand Up @@ -116,3 +117,23 @@ var (
ErrUnauthorized = errors.New("unauthorized")
ErrNotFoundInSession = errors.New("not found in session")
)

func toMap(obj interface{}) map[string]interface{} {
result := make(map[string]interface{})
value := reflect.ValueOf(obj)

if value.Kind() == reflect.Ptr {
value = value.Elem()
}
if value.Kind() != reflect.Struct {
return result
}

typ := reflect.TypeOf(obj)
for i := 0; i < value.NumField(); i++ {
field := typ.Field(i)
fieldValue := value.Field(i)
result[field.Name] = fieldValue.Interface()
}
return result
}
1 change: 1 addition & 0 deletions internal/di/wire.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ func NewServer() *api.Server {
oauth.NewAuthCodeService,
oauth.NewRequestService,
oauth.NewTokenService,
oauth.NewJWKsService,
oauth.NewConfig,
gateway.NewClientRepo,
gateway.NewAuthCodeRepo,
Expand Down
5 changes: 3 additions & 2 deletions internal/di/wire_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 13 additions & 0 deletions internal/usecase/oauth.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,30 @@ import (
"errors"
"fmt"
"slices"

"github.com/lestrrat-go/jwx/jwk"
)

type OAuthUsecase struct {
RequestService *oauth.RequestService
AuthCodeService *oauth.AuthCodeService
ApprovalService *oauth.ApprovalService
TokenService *oauth.TokenService
JWKsService *oauth.JWKsService
ClientRepo oauth.IClientRepo
}

func NewOAuthUsecase(
reqSvc *oauth.RequestService,
authCodeSvc *oauth.AuthCodeService,
jwksService *oauth.JWKsService,
approvalSvc *oauth.ApprovalService,
tokenSvc *oauth.TokenService,
clientRepo oauth.IClientRepo,
) *OAuthUsecase {
return &OAuthUsecase{
RequestService: reqSvc,
JWKsService: jwksService,
AuthCodeService: authCodeSvc,
ApprovalService: approvalSvc,
TokenService: tokenSvc,
Expand Down Expand Up @@ -86,6 +91,14 @@ func (u *OAuthUsecase) RequestToken(req *TokenRequest) (*oauth.AccessToken, *oau
}
}

func (u *OAuthUsecase) GetJWKs() (jwk.Set, error) {
set, err := u.JWKsService.IssueJwks()
if err != nil {
return nil, fmt.Errorf("failed to issue jwks: %w", err)
}
return set, nil
}

var (
ErrPasswordNotMatch = errors.New("invalid password")
ErrNotApproved = errors.New("not approved")
Expand Down
6 changes: 1 addition & 5 deletions spec/pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion spec/schema/@typespec/openapi3/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,8 @@ paths:
content:
application/json:
schema:
type: string
type: object
additionalProperties: {}
/oauth/token:
post:
operationId: OAuthInterface_getToken
Expand Down
2 changes: 1 addition & 1 deletion spec/specs/oauth.tsp
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,6 @@ interface OAuthInterface {
@summary("Get JSON Web Key Set")
getJwks(): {
@statusCode statusCode: 200;
@body body: string;
@body body: Record<unknown>;
};
}

0 comments on commit 3eec2eb

Please sign in to comment.