Documentation ¶
Overview ¶
Package neugo
This package encapsulates some operations on the campus SSO service, in particular CAS, of NEU (cn).
Examples:
E1. Log in to the CAS using account and get the token.
// you can use your own *http.Client instead of creating a new session. client := neugo.NewSession() err := neugo.Use(client).WithAuth("student_id", "password").Login(CAS) token := neugo.About(client).Token(CAS)
E2. Request a service via Web VPN using token.
client := neugo.NewSession() err := neugo.Use(client).WithToken("your_webvpn_token").Login(WebVPN) serviceURL := "https://ipgw.neu.edu.cn" reqURL := neugo.EncryptURLToWebVPN(serviceURL) req := http.NewRequest("GET", reqURL, nil) resp, err := client.Do(req)
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( ErrorAccountBanned = errors.New("account is banned") ErrorAccountNeedsReset = errors.New("account needs reset") ErrorAuthFailed = errors.New("incorrect username or password or cookie") )
var (
ErrorLTNotFound = errors.New("LT not found")
)
Functions ¶
func EncryptURLToWebVPN ¶
EncryptURLToWebVPN encrypts a service url so that it can be accessed via WebVPN.
If the protocol is missed in the provided url, it will be set to http.
Example:
"http://219.216.96.4/eams/homeExt.action" will be encrypted into "https://webvpn.neu.edu.cn/http/77726476706e69737468656265737421a2a618d275613e1e275ec7f8/eams/homeExt.action"
func NewSession ¶
NewSession returns a *http.Client with an empty cookie jar and timeout of 6s.
Types ¶
type ActionSelector ¶
type ActionSelector interface { // Login tries to log in to specific platform. Login(platform Platform) error // DebugLogin does the same as Login except returns response text. DebugLogin(platform Platform) (string, error) }
ActionSelector determines the action to be performed
type AuthSelector ¶
type AuthSelector interface { // WithAuth through username and password on CAS WithAuth(username, password string) ActionSelector // WithToken through platform-dependent token WithToken(token string) ActionSelector }
AuthSelector determines the authentication type
func Use ¶
func Use(client *http.Client) AuthSelector
Use receives a *http.Client, and will add an empty cookie jar if the client doesn't have.
type QuerySelector ¶
type QuerySelector interface { // Token returns the platform-dependent token. // // If no token exists in the session, returns an empty string. Token(platform Platform) string }
QuerySelector determines the info to be queried.
func About ¶
func About(client *http.Client) QuerySelector
About receives a *http.Client so can query some info about the session.