Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using clerk to authenticate via cli tool

I am building a SAAS website that will have a CLI tool as well and am currently looking into how I want to handle AuthN/AuthZ. Ideally I can use the same authentication mechanism for my frontend, backend, and CLI. I'm looking into using clerk for this.

I set it up in a test Next.js app and find it really easy to use on the website portion. What I am not sure about is how to use clerk to authenticate with a CLI.

I'm looking to do something similar to GitHub CLI's gh auth login to generate a token that can be used to authenticate requests and would love it if I could get the CLI login to navigate to my Web UI to generate the token.

Has anyone set this up before and possibly have some code samples?

like image 645
couvq Avatar asked Sep 02 '26 05:09

couvq


2 Answers

I wanted to share that I did some digging through the clerk discord and found an unofficial code example for this using Node.js. Here it is, I plan on using it as a reference for my CLI tool. https://github.com/clerk/cli-auth-unofficial-example

like image 96
couvq Avatar answered Sep 04 '26 20:09

couvq


I had exactly the same use case and I reached out to Clerk's support.

They responded that this is definitely possible and they pointed me to this blog from Turso: https://turso.tech/blog/why-we-transitioned-to-clerk-for-authentication that gives some hints on how they used Clerk with their CLI.

I haven't tried it myself yet but I thought to share it!

like image 29
George Eracleous Avatar answered Sep 04 '26 20:09

George Eracleous



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!