aboutsummaryrefslogtreecommitdiffhomepage
path: root/backend/auth/fortee/fortee.go
diff options
context:
space:
mode:
authornsfisis <nsfisis@gmail.com>2024-08-11 13:28:13 +0900
committernsfisis <nsfisis@gmail.com>2024-08-11 14:18:34 +0900
commit97fdb23b7a1b75001a2ca53ea5ec76c52c57dde3 (patch)
tree7aa0a50700804083a1f8cff3659dbb9c922fd0c5 /backend/auth/fortee/fortee.go
parent729bd4e58ebfc1a46fa69f09179effe83b5b28cb (diff)
downloadphperkaigi-2025-albatross-97fdb23b7a1b75001a2ca53ea5ec76c52c57dde3.tar.gz
phperkaigi-2025-albatross-97fdb23b7a1b75001a2ca53ea5ec76c52c57dde3.tar.zst
phperkaigi-2025-albatross-97fdb23b7a1b75001a2ca53ea5ec76c52c57dde3.zip
refactor(backend): define OpenAPI spec of fortee login API
Diffstat (limited to 'backend/auth/fortee/fortee.go')
-rw-r--r--backend/auth/fortee/fortee.go42
1 files changed, 42 insertions, 0 deletions
diff --git a/backend/auth/fortee/fortee.go b/backend/auth/fortee/fortee.go
new file mode 100644
index 0000000..7f9d816
--- /dev/null
+++ b/backend/auth/fortee/fortee.go
@@ -0,0 +1,42 @@
+package fortee
+
+import (
+ "context"
+ "errors"
+ "net/http"
+)
+
+const (
+ apiEndpoint = "https://fortee.jp"
+)
+
+var (
+ ErrLoginFailed = errors.New("fortee login failed")
+)
+
+func LoginFortee(ctx context.Context, username string, password string) error {
+ client, err := NewClientWithResponses(apiEndpoint, WithRequestEditorFn(addAcceptHeader))
+ if err != nil {
+ return err
+ }
+ res, err := client.PostLoginWithFormdataBodyWithResponse(ctx, PostLoginFormdataRequestBody{
+ Username: username,
+ Password: password,
+ })
+ if err != nil {
+ return err
+ }
+ if res.StatusCode() != http.StatusOK {
+ return ErrLoginFailed
+ }
+ if !res.JSON200.LoggedIn {
+ return ErrLoginFailed
+ }
+ return nil
+}
+
+// fortee API denies requests without Accept header.
+func addAcceptHeader(_ context.Context, req *http.Request) error {
+ req.Header.Set("Accept", "application/json")
+ return nil
+}