Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
cateiru committed Jan 11, 2024
1 parent 26520ca commit 6e627e3
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 13 deletions.
12 changes: 6 additions & 6 deletions src/__snapshots__/fedcm_handler_test.snap
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ src.FedCMClientMetadataResponse{PrivacyPolicyUrl:"http://cateiru.test/policy", T

[TestFedCMConfigHandler/取得可能 - 1]
src.FedCMConfigResponse{
IDTokenEndpoint: "/v2/fedcm/id_assertion",
IDTokenEndpoint2: "/v2/fedcm/id_assertion",
ClientIdMetadataEndpoint: "/v2/fedcm/client_metadata",
IDTokenEndpoint: "http://localhost:8080/fedcm/id_assertion",
IDTokenEndpoint2: "http://localhost:8080/fedcm/id_assertion",
ClientIdMetadataEndpoint: "http://localhost:8080/fedcm/client_metadata",
SignInUrl: "http://cateiru.test/login",
LoginUrl: "http://cateiru.test/login",
AccountsEndpoint: "/v2/fedcm/accounts",
ClientMetadataEndpoint: "/v2/fedcm/client_metadata",
IdAssertionEndpoint: "/v2/fedcm/id_assertion",
AccountsEndpoint: "http://localhost:8080/fedcm/accounts",
ClientMetadataEndpoint: "http://localhost:8080/fedcm/client_metadata",
IdAssertionEndpoint: "http://localhost:8080/fedcm/id_assertion",
DisconnectEndpoint: "",
Branding: &src.FedCMConfigBranding{
BackgroundColor: "#ffffff",
Expand Down
33 changes: 26 additions & 7 deletions src/fedcm_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ type FedCMConfigBranding struct {
BackgroundColor string `json:"background_color,omitempty"`
Color string `json:"color,omitempty"`
Name string `json:"name,omitempty"`
Icons []FedCMConfigIcons `json:"icons"`
Icons []FedCMConfigIcons `json:"icons,omitempty"`
}

type FedCMConfigIcons struct {
Expand Down Expand Up @@ -87,6 +87,7 @@ func (h *Handler) WebIdentityHandler(c echo.Context) error {

// FedCM の設定レスポンス
func (h *Handler) FedCMConfigHandler(c echo.Context) error {
apiUrl := h.C.Host.String()
pageUrl := h.C.SiteHost.String()

signInUrl, err := url.Parse(pageUrl)
Expand All @@ -95,20 +96,38 @@ func (h *Handler) FedCMConfigHandler(c echo.Context) error {
}
signInUrl.Path = "/login"

accountsEndpoint, err := url.Parse(apiUrl)
if err != nil {
return err
}
accountsEndpoint.Path = "/fedcm/accounts"

clientMetadataEndpoint, err := url.Parse(apiUrl)
if err != nil {
return err
}
clientMetadataEndpoint.Path = "/fedcm/client_metadata"

idAssertionEndpoint, err := url.Parse(apiUrl)
if err != nil {
return err
}
idAssertionEndpoint.Path = "/fedcm/id_assertion"

return c.JSON(http.StatusOK, &FedCMConfigResponse{
AccountsEndpoint: "/v2/fedcm/accounts",
ClientMetadataEndpoint: "/v2/fedcm/client_metadata",
IdAssertionEndpoint: "/v2/fedcm/id_assertion",
AccountsEndpoint: accountsEndpoint.String(),
ClientMetadataEndpoint: clientMetadataEndpoint.String(),
IdAssertionEndpoint: idAssertionEndpoint.String(),
Branding: &FedCMConfigBranding{
BackgroundColor: h.C.BrandBackgroundColor,
Color: h.C.BrandColor,
Name: h.C.BrandName,
// TODO: アイコン埋める
},

IDTokenEndpoint: "/v2/fedcm/id_assertion",
IDTokenEndpoint2: "/v2/fedcm/id_assertion",
ClientIdMetadataEndpoint: "/v2/fedcm/client_metadata",
IDTokenEndpoint: idAssertionEndpoint.String(),
IDTokenEndpoint2: idAssertionEndpoint.String(),
ClientIdMetadataEndpoint: clientMetadataEndpoint.String(),
SignInUrl: signInUrl.String(),
LoginUrl: signInUrl.String(),
})
Expand Down

0 comments on commit 6e627e3

Please sign in to comment.