CodeSwitch

Any language, any framework, always secure

Integrate authentication into your APIs effortlessly with just a few lines of code. We offer SDKs for various languages and frameworks, alongside an intuitive REST API with a public OpenAPI specification

import { verifyKey } from @codeswitch/api'

    const { result, error } = await verifyKey({
        apiId: 'api_123',
        key: 'xyz_123'
    })

    if (error) {
        // handle network error
    }

    if (!result.valid) {
        //reject unauthorized request
    }

    // handle request
                        
import asyncio
    import os
    import codeswitch

    async def main() -> None:
        client = codeswitch.Client(api_key=os.environ["API_KEY"])
        await client.start()

        result = await client.keys.verify_key("prefix_abc123")

        if result.is_ok {
            print(data.valid);
        } else {
            print(result.unwrap_err());
        }
                        
use codeswitch::models::{VerifyKeyRequest, Wrapped};
    use codeswitch::Client;

    async fn verify_key() {
        let api_key = env::var("codeswitch_API_KEY").expect("Environment variable CODESWITCH_API_KEY not found");
        let c = Client::new(&api_key);
        let req = VerifyKeyRequest::new("test_req", "api_458vdYdbwut5LWABzXZP3Z8jPVas");

        match c.verify_key(req).await {
            Wrapped::Ok(res) => println!("{{res:?}}"),
            Wrapped::Err(err) => eprintln!("{{err:?}}"),
        }
    }
                        
package main

    import (
        "fmt"
        codeswitch "github.com/WilfredAlmeida/codeswitch-go/features"
    )

    func main() {
        apiKey := "key_3ZZ7faJrkfv1YAfhfAcnKW74";
        response, err := codeswitch.KeyVerify(apiKey);
        if err != nil {
            fmt.Println("Error:", err);
            return;
        }

        if response.Valid {
            fmt.Println("Key is valid");
        } else {
            fmt.Println("Key is invalid");
        }
    }
                        
curl --request POST \
    --url https://api.codeswitch.dev/v1/keys.verifyKey \
    --header 'Content-Type: application/json' \
    --data '{
        "apiId": "api_1234",
        "key": "sk_1234",
    }'
                        
CodeswitchElixirSdk.verify_key("xyz_AS5HDbkXXPot2MMoPHD8jnL")

    # returns
    %{
        "valid" => true,
        "ownerId" => "chronak",
        "meta" => %{
            "hello" => "world"
        }
    }
                        
package com.example.myapp;
    import com.codeswitch.codeswitchsdk.dto.KeyVerifyRequest;
    import com.codeswitch.codeswitchsdk.dto.KeyVerifyResponse;

    @RestController
    public class APIController {

        private static IKeyService keyService = new KeyService();

        @PostMapping("/verify")
        public KeyVerifyResponse verifyKey(
            @RequestBody KeyVerifyRequest keyVerifyRequest) {
            // Delegate the creation of the key to the KeyService from the SDK
            return keyService.verifyKey(keyVerifyRequest);
        }
    }
                        

oss/acc

Open-source

We believe strongly in the value of open source: our codebase and development process is available to learn from and remix.

View on Github
GitPulse