| 1 |
package proton |
| 2 |
|
| 3 |
import ( |
| 4 |
"context" |
| 5 |
|
| 6 |
"github.com/go-resty/resty/v2" |
| 7 |
) |
| 8 |
|
| 9 |
func (c *Client) Auth2FA(ctx context.Context, req Auth2FAReq) error { |
| 10 |
return c.do(ctx, func(r *resty.Request) (*resty.Response, error) { |
| 11 |
return r.SetBody(req).Post("/auth/v4/2fa") |
| 12 |
}) |
| 13 |
} |
| 14 |
|
| 15 |
func (c *Client) AuthDelete(ctx context.Context) error { |
| 16 |
return c.do(ctx, func(r *resty.Request) (*resty.Response, error) { |
| 17 |
return r.Delete("/auth/v4") |
| 18 |
}) |
| 19 |
} |
| 20 |
|
| 21 |
func (c *Client) AuthSessions(ctx context.Context) ([]AuthSession, error) { |
| 22 |
var res struct { |
| 23 |
Sessions []AuthSession |
| 24 |
} |
| 25 |
|
| 26 |
if err := c.do(ctx, func(r *resty.Request) (*resty.Response, error) { |
| 27 |
return r.SetResult(&res).Get("/auth/v4/sessions") |
| 28 |
}); err != nil { |
| 29 |
return nil, err |
| 30 |
} |
| 31 |
|
| 32 |
return res.Sessions, nil |
| 33 |
} |
| 34 |
|
| 35 |
func (c *Client) AuthRevoke(ctx context.Context, authUID string) error { |
| 36 |
return c.do(ctx, func(r *resty.Request) (*resty.Response, error) { |
| 37 |
return r.Delete("/auth/v4/sessions/" + authUID) |
| 38 |
}) |
| 39 |
} |
| 40 |
|
| 41 |
func (c *Client) AuthRevokeAll(ctx context.Context) error { |
| 42 |
return c.do(ctx, func(r *resty.Request) (*resty.Response, error) { |
| 43 |
return r.Delete("/auth/v4/sessions") |
| 44 |
}) |
| 45 |
} |