login-anthropic.ts 971 B

12345678910111213141516171819202122
  1. import { AuthAnthropic } from "../../auth/anthropic"
  2. import { UI } from "../ui"
  3. // Example: https://claude.ai/oauth/authorize?code=true&client_id=9d1c250a-e61b-44d9-88ed-5944d1962f5e&response_type=code&redirect_uri=https%3A%2F%2Fconsole.anthropic.com%2Foauth%2Fcode%2Fcallback&scope=org%3Acreate_api_key+user%3Aprofile+user%3Ainference&code_challenge=MdFtFgFap23AWDSN0oa3-eaKjQRFE4CaEhXx8M9fHZg&code_challenge_method=S256&state=rKLtaDzm88GSwekyEqdi0wXX-YqIr13tSzYymSzpvfs
  4. import { generatePKCE } from "@openauthjs/openauth/pkce"
  5. export const LoginAnthropicCommand = {
  6. command: "anthropic",
  7. describe: "Login to Anthropic",
  8. handler: async () => {
  9. const { url, verifier } = await AuthAnthropic.authorize()
  10. UI.print("Login to Anthropic")
  11. UI.print("Open the following URL in your browser:")
  12. UI.print(url)
  13. UI.print("")
  14. const code = await UI.input("Paste the authorization code here: ")
  15. await AuthAnthropic.exchange(code, verifier)
  16. },
  17. }