API-Auth examples
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 start-api 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 create-api 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
Deploy the created API Task using the deploy command. This makes it available for execution by Task Requesters.
truebit deploy <namespace> <taskname> --taskId <taskId>
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.
Last updated
Was this helpful?