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
                    
                
                    
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:?}}"),
            }
        }
                    
                
                     
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);
   }
}
                    
                
                    
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());
    }
                    
                
                    
GRANT SELECT ON api_keys TO api_key;
SELECT valid FROM api_keys WHERE api_key = 'prefix_abc123';
                    
                

oss/acc

Open-Source

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

GitPulse
circuit board graphic