#cas #system #logging #rustls #blocking #ticket #ustc

ustc_cas

a simple library for logging into USTC CAS System

6 releases

0.2.0 Sep 5, 2023
0.1.4 Feb 17, 2023
0.1.1 Jan 27, 2023

#8 in #cas

Custom license

38KB
542 lines

ustc_cas

crates.io documentation

a rust library for logging into USTC CAS System.


lib.rs:

a simple library for logging into USTC CAS System.

Usage

All you should do is call get_ticket. The function param service_url can be found from browser's address bar when logging into CAS by hand. The returned ticket value can be used for further authentication specific to websites.

ustc_cas::get_ticket is an async function and requires a async runtime to execute. While ustc_cas::blocking::get_ticket, enabled by blocking feature, can not be used in an aysnc runtime. It with block the current thread before returning.

Example

use tokio::runtime::Builder;

 let runtime = Builder::new_current_thread()
    .enable_io()
    .enable_time()
    .build()
    .unwrap();

    let result = runtime.block_on(ustc_cas::get_ticket(
    "PB00000000",
    "12345678",
    "https://jw.ustc.edu.cn/ucas-sso/login",
 ));

 match result {
    Ok(s) => {
        println!("ticket: {s}");
    },
    Err(e) => {
        println!("Error: {e}");
    }
 }

Features

  • validate-code: Validate code recognition using image and bytes crate. get_ticket function will panic if this feature is disabled but validate code is requested. Enabled by default.
  • blocking: provide blocking version of get_ticket function.
  • native-tls: Use system tls library. Enabled by default.
  • rustls-tls: Use rustls for tls functionality.

Dependencies

~7–20MB
~289K SLoC