Documentation
¶
Overview ¶
Package mlearning implements the mlearning.sjtu.edu.cn attendance endpoints: the SSO chain that plants the domain's Access_Token cookie, the two read projections behind /courses/<id>/attendance, and the scan-submit write of `sjtu attendance submit`.
Token model: a JAAuthCookie-authenticated visit to any forscan URL rides the SSO chain and ends with the callback planting a `token` cookie in the mlearning domain. That cookie is the student client's Access_Token and authenticates API requests as a bare Authorization header value, without a Bearer prefix (verified against the live service on 2026-10-01).
A dead Access_Token is rejected in the business layer, never as 401: the API answers HTTP 200 carrying {"resultCode":"10001"} ("token不存在,请 重新登录!"). Reads detect that shape, clear the planted token, re-run the SSO chain, and retry once; a persistent rejection passes through verbatim for the caller to judge.
Index ¶
- Variables
- func ValidateForscanURL(rawURL string) (rollCallToken, signHistoryID string, err error)
- type Client
- func (c *Client) Records(ctx context.Context, courseID int64) (json.RawMessage, error)
- func (c *Client) Self(ctx context.Context) (json.RawMessage, error)
- func (c *Client) Status(ctx context.Context, courseID int64) (json.RawMessage, error)
- func (c *Client) Submit(ctx context.Context, rawURL string) (json.RawMessage, error)
Constants ¶
This section is empty.
Variables ¶
var ErrAuth = errors.New("jaccount authentication required; run `sjtu auth jaccount login`")
ErrAuth reports an expired or missing jAccount session: the SSO chain bounced back to the login host instead of reaching mlearning.
var ErrInvalidURL = errors.New("not an mlearning forscan URL")
ErrInvalidURL rejects a scanned QR URL that is not a well-formed forscan link; the CLI maps it to a usage error.
Functions ¶
func ValidateForscanURL ¶
ValidateForscanURL checks a scanned QR URL and extracts its roll-call parameters: https scheme, mlearning host, the forscan path prefix, and non-empty rollCallToken/signHistoryId query parameters.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client talks to mlearning over a cookie session holding a valid JAAuthCookie.
func New ¶
New builds a Client over the given cookie session; the session must carry a JAAuthCookie for the jAccount domain family.
func (*Client) Records ¶
Records lists the caller's sign-in records of the course, as the raw sign/records response with the UI's own paging parameters.
func (*Client) Self ¶ added in v0.5.0
Self fetches the caller's identity as the raw users/self response. It is the mlearning domain's lightweight health probe: a live token answers 200 with the identity body, a dead one the 10001 rejection.
func (*Client) Status ¶
Status reports whether the course has a roll call in progress, as the raw existentB response (idle state: {"resultCode":"200","body":{}}).