9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
|
# File 'lib/easyai/auth/authclaude.rb', line 9
def self.configure(config, user_name = nil)
return false unless config
is_macos = RUBY_PLATFORM.include?('darwin')
keychain_exists = is_macos && config["key_chain"] && config["key_chain"]["claudeAiOauth"] && config["key_chain"]["service_name"]
env_token_exists = config["env"] && config["env"]["CLAUDE_CODE_OAUTH_TOKEN"]
if keychain_exists
token_from_keychain = get_token_from_keychain(config["key_chain"]["service_name"])
if token_from_keychain
config["env"] ||= {}
config["env"]["CLAUDE_CODE_OAUTH_TOKEN"] = token_from_keychain
end
end
if keychain_exists
configure_keychain(config)
clean_env_variables
elsif env_token_exists
verify_token_config(config)
clean_keychain if is_macos
else
token = prompt_for_token
return false if token.nil? || token.empty?
config["env"] ||= {}
config["env"]["CLAUDE_CODE_OAUTH_TOKEN"] = token
verify_token_config(config)
clean_keychain
end
update_claude_json(config) if config["claude_json"]
configure_proxy(config) if config["claude_proxy"]
true
end
|