xjtuorg

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Mar 13, 2025 License: MIT Imports: 14 Imported by: 0

README

XJTUORG

XJTU authentication module in Go

Usage
import (
	"net/http"
	"net/http/cookiejar"

    "github.com/endaytrer/xjtuorg"
)

// the parameter is whether to login as mobile
login_session := xjtuorg.New(true)

netid := "3124100000"
passwd := "password123"

// The login process would not begin before calling `Login`.
redir, err := login_session.Login("https://example.com/web/cas/login.html", netid, password)

if err != nil {
    // deal with error
}

// Now request with session to `redir`
client := http.Client{Jar: cookiejar.New(nil)}
_, err := client.Get(redir)

if err != nil {
    // deal with error
}

// Now you are logged in!
// Use `client` to make requests.

Documentation

Index

Constants

View Source
const Phase1Url = "https://org.xjtu.edu.cn/openplatform/g/admin/login"
View Source
const Phase2Url = "https://org.xjtu.edu.cn/openplatform/g/admin/getUserIdentity"
View Source
const Phase3Url = "https://org.xjtu.edu.cn/openplatform/oauth/auth/getRedirectUrl"

Variables

This section is empty.

Functions

This section is empty.

Types

type ContentType

type ContentType string
const (
	None ContentType = "none"
	Json ContentType = "application/json"
	Form ContentType = "application/x-www-form-urlencoded"
)

type GeneralResponse

type GeneralResponse struct {
	Code    int         `json:"code"`
	Message string      `json:"message"`
	Data    interface{} `json:"data"`
}

type LoginError

type LoginError int
const (
	RequestError LoginError = iota
	ApiError
	NoIdentity
)

func (LoginError) Error

func (t LoginError) Error() string

type XjtuOrg

type XjtuOrg struct {
	// contains filtered or unexported fields
}

func New

func New(mobile bool) XjtuOrg

func (*XjtuOrg) Login

func (t *XjtuOrg) Login(login_url, username, password string) (redir_url string, err error)

Jump to

Keyboard shortcuts

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