neugo

package module
v0.4.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 8, 2022 License: MIT Imports: 13 Imported by: 3

README

NEU API

Codecov Go Report Card Latest Tag

Documentation

See pkg.go.dev/github.com/neucn/neugo.

License

MIT License.

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

View Source
var (
	ErrorAccountBanned     = errors.New("account is banned")
	ErrorAccountNeedsReset = errors.New("account needs reset")
	ErrorAuthFailed        = errors.New("incorrect username or password or cookie")
)
View Source
var (
	ErrorLTNotFound = errors.New("LT not found")
)

Functions

func EncryptURLToWebVPN added in v0.4.0

func EncryptURLToWebVPN(url string) string

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

func NewSession() *http.Client

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 Platform

type Platform = byte

Platform is the platform providing authentication service.

const (
	// CAS pass.neu.edu.cn
	CAS Platform = iota
	// WebVPN webvpn.neu.edu.cn
	WebVPN
)

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL