https://github.com/limeskey/hackclub-verifier-api
https://github.com/limeskey/hackclub-verifier-api
Last synced: 2 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/limeskey/hackclub-verifier-api
- Owner: LimesKey
- Created: 2024-08-25T18:27:25.000Z (almost 2 years ago)
- Default Branch: main
- Last Pushed: 2024-11-20T22:44:25.000Z (over 1 year ago)
- Last Synced: 2026-03-09T19:46:08.367Z (4 months ago)
- Language: Rust
- Homepage: https://api.onboard.limeskey.com
- Size: 263 KB
- Stars: 1
- Watchers: 1
- Forks: 2
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# OnBoard Submission Verifier
This program runs as a Cloudflare Wrangler worker at [api.onboard.limeskey.com](https://api.onboard.limeskey.com). It's intended to be used by the Svelte, Rust & WebAssembly frontend at [verify.onboard.hackclub.com](https://verify.onboard.hackclub.com), also hosted by Cloudflare in a Page.
This API is used to verify users using Slack and GitHub oAuth codes. The API accepts POST requests with optional Slack and GitHub authorization codes and returns a json struct that includes information about the Slack User and GitHub user, and also checks against the unified YSWS Verification API to see if they're eligible and have verified their ID.
### Endpoint
```
POST https://api.onboard.limeskey.com/api
```
### Request Payload
The request payload should be in JSON format and can include either or both Slack and GitHub authorization codes.
#### Example Payload
```json
{
"slack_code": "your_slack_code_here",
"github_code": "your_github_code_here"
}
```
- `slack_code` *(optional)*: The Slack OAuth code.
- `github_code` *(optional)*: The GitHub OAuth code.
### Response
If the request is successful, the API will return a 200 response with a URL containing verification information, which includes:
- `secret`: The hashed secret.
- `slack_id`: The Slack user ID.
- `eligibility`: The user's eligibility status from Slack.
- `slack_user`: The Slack username.
- `github_id`: The GitHub user ID.
#### Example Response
```
https://forms.hackclub.com/t/9yNy4WYtrZus?secret=5ec501bbb97b6b&slack_id=U04JGJN2B40&eligibility=EligibleL1&slack_user=Ryan+Di+Lorenzo&github_id=LimesKey
```
### Error Handling
If the request fails, the API will return an error message with the response status.
#### Example Error
```
{
"error": "Request failed with status: 400"
}
```
### Example Usage
```rust
// Example using Fetch API in Rust using wasm_bindgen
#[derive(Serialize, Deserialize)]
struct ApiPayload {
slack_code: Option,
github_code: Option,
}
pub async fn verify_api(slack_code: Option, github_code: Option) -> Result {
let payload = ApiPayload { slack_code, github_code };
let payload_json = serde_json::to_string(&payload).unwrap();
let mut opts = RequestInit::new();
opts.method("POST")
.body(Some(&JsValue::from_str(&payload_json)))
.mode(RequestMode::Cors);
let request = Request::new_with_str_and_init("https://api.onboard.limeskey.com/api", &opts).unwrap();
let response_value = JsFuture::from(web_sys::window().unwrap().fetch_with_request(&request)).await?;
let response_text = JsFuture::from(response_value.dyn_into::()?.text()?).await?;
Ok(response_text)
}
```
### Development
Build the program using `pnpm install` and run `pnpm wrangler dev` with the required enviornment variables.