Skip to content

Commit bab5069

Browse files
committed
Reapply "move ruby to a script"
This reverts commit 9db1e0a.
1 parent 9db1e0a commit bab5069

File tree

2 files changed

+71
-65
lines changed

2 files changed

+71
-65
lines changed
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
#!/usr/bin/env ruby
2+
3+
require 'securerandom'
4+
require 'uri'
5+
require 'json'
6+
require 'digest'
7+
require 'base64'
8+
9+
class ClaudeLoginStart
10+
OAUTH_AUTHORIZE_URL = 'https://claude.ai/oauth/authorize'
11+
CLIENT_ID = '9d1c250a-e61b-44d9-88ed-5944d1962f5e'
12+
REDIRECT_URI = 'https://console.anthropic.com/oauth/code/callback'
13+
STATE_FILE = 'claude_oauth_state.json'
14+
15+
def generate_login_url
16+
state = SecureRandom.hex(32)
17+
code_verifier = SecureRandom.urlsafe_base64(32)
18+
code_challenge = Base64.urlsafe_encode64(Digest::SHA256.digest(code_verifier)).chomp('=')
19+
20+
# Save state and code verifier for verification later
21+
save_state(state, code_verifier)
22+
23+
params = {
24+
'code' => 'true',
25+
'client_id' => CLIENT_ID,
26+
'response_type' => 'code',
27+
'redirect_uri' => REDIRECT_URI,
28+
'scope' => 'org:create_api_key user:profile user:inference',
29+
'code_challenge' => code_challenge,
30+
'code_challenge_method' => 'S256',
31+
'state' => state
32+
}
33+
34+
url = "#{OAUTH_AUTHORIZE_URL}?" + URI.encode_www_form(params)
35+
36+
puts url
37+
38+
url
39+
end
40+
41+
private
42+
43+
def save_state(state, code_verifier)
44+
state_data = {
45+
'state' => state,
46+
'code_verifier' => code_verifier,
47+
'timestamp' => Time.now.to_i,
48+
'expires_at' => Time.now.to_i + 600 # 10 minutes
49+
}
50+
51+
File.write(STATE_FILE, JSON.pretty_generate(state_data))
52+
rescue => e
53+
puts "Warning: Could not save state file: #{e.message}"
54+
end
55+
end
56+
57+
if __FILE__ == $0
58+
if ARGV.include?('--help') || ARGV.include?('-h')
59+
puts "Usage: #{$0}"
60+
puts " Generates an OAuth login URL for Claude Code authentication"
61+
puts " --help, -h Show this help message"
62+
exit 0
63+
end
64+
65+
login = ClaudeLoginStart.new
66+
login.generate_login_url
67+
end

.github/workflows/claude-oauth-login.yml

Lines changed: 4 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Claude OAuth Login
1+
name: Claude OAuth Login (Simple)
22

33
on:
44
workflow_dispatch:
@@ -25,69 +25,8 @@ jobs:
2525
run: |
2626
if [ -z "${{ inputs.authorization_code }}" ]; then
2727
# No code provided, generate URL
28-
cat << 'EOF' > login_start.rb
29-
#!/usr/bin/env ruby
30-
31-
require 'securerandom'
32-
require 'uri'
33-
require 'json'
34-
require 'digest'
35-
require 'base64'
36-
37-
class ClaudeLoginStart
38-
OAUTH_AUTHORIZE_URL = 'https://claude.ai/oauth/authorize'
39-
CLIENT_ID = '9d1c250a-e61b-44d9-88ed-5944d1962f5e'
40-
REDIRECT_URI = 'https://console.anthropic.com/oauth/code/callback'
41-
STATE_FILE = 'claude_oauth_state.json'
42-
43-
def generate_login_url
44-
state = SecureRandom.hex(32)
45-
code_verifier = SecureRandom.urlsafe_base64(32)
46-
code_challenge = Base64.urlsafe_encode64(Digest::SHA256.digest(code_verifier)).chomp('=')
47-
48-
# Save state and code verifier for verification later
49-
save_state(state, code_verifier)
50-
51-
params = {
52-
'code' => 'true',
53-
'client_id' => CLIENT_ID,
54-
'response_type' => 'code',
55-
'redirect_uri' => REDIRECT_URI,
56-
'scope' => 'org:create_api_key user:profile user:inference',
57-
'code_challenge' => code_challenge,
58-
'code_challenge_method' => 'S256',
59-
'state' => state
60-
}
61-
62-
url = "#{OAUTH_AUTHORIZE_URL}?" + URI.encode_www_form(params)
63-
64-
puts url
65-
66-
url
67-
end
68-
69-
private
70-
71-
def save_state(state, code_verifier)
72-
state_data = {
73-
'state' => state,
74-
'code_verifier' => code_verifier,
75-
'timestamp' => Time.now.to_i,
76-
'expires_at' => Time.now.to_i + 600 # 10 minutes
77-
}
78-
79-
File.write(STATE_FILE, JSON.pretty_generate(state_data))
80-
rescue => e
81-
puts "Warning: Could not save state file: #{e.message}"
82-
end
83-
end
84-
85-
login = ClaudeLoginStart.new
86-
login.generate_login_url
87-
EOF
88-
89-
chmod +x login_start.rb
90-
oauth_url=$(ruby login_start.rb)
28+
chmod +x .github/scripts/claude_oauth_login.rb
29+
oauth_url=$(.github/scripts/claude_oauth_login.rb)
9130
9231
echo "## 🔐 Claude OAuth Login Instructions" >> $GITHUB_STEP_SUMMARY
9332
echo "" >> $GITHUB_STEP_SUMMARY
@@ -99,7 +38,7 @@ jobs:
9938
echo "" >> $GITHUB_STEP_SUMMARY
10039
echo "### Step 2: Run Workflow Again" >> $GITHUB_STEP_SUMMARY
10140
echo "" >> $GITHUB_STEP_SUMMARY
102-
echo "1. Go to the [Actions tab](${{ github.server_url }}/${{ github.repository }}/actions/workflows/claude-oauth-login-secure.yml)" >> $GITHUB_STEP_SUMMARY
41+
echo "1. Go to the [Actions tab](${{ github.server_url }}/${{ github.repository }}/actions/workflows/claude-oauth-login-simple.yml)" >> $GITHUB_STEP_SUMMARY
10342
echo "2. Click 'Run workflow'" >> $GITHUB_STEP_SUMMARY
10443
echo "3. Paste the authorization code in the input field" >> $GITHUB_STEP_SUMMARY
10544
echo "4. Click 'Run workflow' to process the code" >> $GITHUB_STEP_SUMMARY

0 commit comments

Comments
 (0)