diff options
Diffstat (limited to 'backend/auth/fortee/fortee.go')
| -rw-r--r-- | backend/auth/fortee/fortee.go | 46 |
1 files changed, 0 insertions, 46 deletions
diff --git a/backend/auth/fortee/fortee.go b/backend/auth/fortee/fortee.go deleted file mode 100644 index 25ca9c5..0000000 --- a/backend/auth/fortee/fortee.go +++ /dev/null @@ -1,46 +0,0 @@ -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) (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 - } - resOk := res.JSON200 - if !resOk.LoggedIn { - return "", ErrLoginFailed - } - if resOk.User == nil { - return "", ErrLoginFailed - } - return resOk.User.Username, nil -} - -// fortee API denies requests without Accept header. -func addAcceptHeader(_ context.Context, req *http.Request) error { - req.Header.Set("Accept", "application/json") - return nil -} |
