Truebit Verify
  • Getting Started
    • 📄What is Truebit Verify?
      • How does Truebit work?
      • System Actors
    • ⏱️Get Started
    • ⚙️Architecture
      • Truebit Verify Hub
      • Truebit Verify Nodes
      • What is a transcript?
        • Transcript example
        • API Transcript example
    • Key Concepts
      • What is verification?
      • Determinism
      • WebAssembly
      • Task instrumentation
  • Developing Truebit Tasks
    • Introduction
    • Writing Function Tasks
      • Supported languages
        • Javascript
        • Python
        • Rust
    • Writing API Tasks
    • Task examples
      • Function Task examples
        • Fibonacci
        • Reverse Alphabet
        • Encrypt sha256 using bun.js
        • Encrypt sha256 using Deno
        • ECDSA signature verification
        • NumPy example
      • API Task examples
        • Pet Store CRUD
        • API-Auth examples
    • Namespace management
    • Task Authorization
    • Truebit CLI
      • secret.json
  • Executing Truebit tasks
    • Introduction
    • Task Execution API
      • Execute Function Tasks
      • Execute API Tasks
      • Get Task Status
    • Transcript API
      • Get Transcript
      • Get Invoice
  • Community
    • Truebit Unchained Protocol
    • Support
Powered by GitBook
On this page
  • 1. Test Your Manifest
  • 2. Create the Truebit API Task
  • 3. Deploy the Truebit API Task
  • 4. Deploy the Authentication Credentials
  • 5. Execute the Truebit API Task

Was this helpful?

  1. Developing Truebit Tasks
  2. Task examples
  3. API Task examples

API-Auth examples

PreviousPet Store CRUDNextNamespace management

Last updated 16 days ago

Was this helpful?

The main goal of these examples is to demonstrate how a Task Developer can create Truebit API Tasks that interact with authenticated endpoints. We’ll walk through how to handle each of the supported authentication methods: custom-header, basic-auth, and aws-signature.

1. Test Your Manifest

Use the command to execute the API task locally within the context of the Truebit Node. This allows you to verify that the authenticated endpoints behave as expected.

custom-header

truebit start-api api-auth/custom-header/custom-header.manifest.json api-auth/custom-header/custom-header.input.json custom-header 'username:foo, password:bar'

basic-auth

truebit start-api api-auth/basic-auth/basic-auth.manifest.json api-auth/basic-auth/basic-auth.input.json basic-auth 'username:<username>,password:<password>'

aws-signature

truebit start-api api-auth/aws-signature/aws-signature.manifest.json api-auth/aws-signature/aws-signature.input.json aws-signature "accessKey:AKIA2VXUSRQO3CTJ5UH5,secretKey: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"

2. Create the Truebit API Task

Once the authenticated endpoints have been successfully tested, create the Truebit API Task by running the command.

custom-header

truebit create-api api-auth/custom-header/custom-header.manifest.json

basic-auth

truebit create-api api-auth/basic-auth/basic-auth.manifest.json

aws-signature

truebit create-api api-auth/aws-signature/aws-signature.manifest.json

3. Deploy the Truebit API Task

truebit deploy <namespace> <taskname> --taskId <taskId>

Replace the <taskId> with the generate taskId from the previous step

4. Deploy the Authentication Credentials

After deploying the API Task, upload the required authentication credentials using the api-auth command. This ensures the Task Requester can execute the task without encountering authentication issues.

custom-header

truebit api-auth <namespace> <taskname> <taskId> custom-header "username:<username>,password:<password>"

basic-auth

truebit api-auth <namespace> <taskname> <taskId> basic-auth 'username:<username>,password:<password>'

aws-signature

truebit api-auth <namespace> <taskname> <taskId> aws-signature "accessKey:AKIA2VXUSRQO3CTJ5UH5,secretKey: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"

5. Execute the Truebit API Task

You’re now ready to execute the Truebit API Task using the execute-by-name endpoint and retrieve the Truebit transcript.

Deploy the created API Task using the command. This makes it available for execution by Task Requesters.

start-api
create-api
deploy