Class: Legion::Extensions::MicrosoftTeams::CLI::Auth
- Inherits:
-
Object
- Object
- Legion::Extensions::MicrosoftTeams::CLI::Auth
- Includes:
- Helpers::Lex
- Defined in:
- lib/legion/extensions/microsoft_teams/cli/auth.rb
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.cli_alias ⇒ Object
14 15 16 |
# File 'lib/legion/extensions/microsoft_teams/cli/auth.rb', line 14 def self.cli_alias 'teams' end |
.descriptions ⇒ Object
18 19 20 21 22 23 |
# File 'lib/legion/extensions/microsoft_teams/cli/auth.rb', line 18 def self.descriptions { login: 'Authenticate with Microsoft Teams via browser OAuth', status: 'Show current Teams authentication state' } end |
Instance Method Details
#login(tenant_id: nil, client_id: nil) ⇒ Object
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 53 |
# File 'lib/legion/extensions/microsoft_teams/cli/auth.rb', line 25 def login(tenant_id: nil, client_id: nil) settings = resolve_settings tid = tenant_id || settings[:tenant_id] || ENV.fetch('AZURE_TENANT_ID', nil) cid = client_id || settings[:client_id] || ENV.fetch('AZURE_CLIENT_ID', nil) log.debug("Resolved tenant_id=#{tid ? 'present' : 'nil'}, client_id=#{cid ? 'present' : 'nil'}") unless tid && cid puts 'Error: tenant_id and client_id required (set in settings, env vars, or pass as args)' return end log.info('Starting Teams delegated auth login') browser_auth = Helpers::BrowserAuth.new(tenant_id: tid, client_id: cid, force_local_server: true) result = browser_auth.authenticate body = result&.dig(:result) if body&.dig('access_token') log.info('Authentication successful, storing token') store_token(body) puts 'Teams authenticated successfully.' else log.warn("Authentication result: #{result&.keys&.join(', ') || 'nil'}") puts 'Teams authentication failed or was cancelled.' end rescue StandardError => e log.error("Login failed: #{e.}") puts "Error: #{e.}" end |
#status ⇒ Object
55 56 57 58 59 60 61 62 63 64 |
# File 'lib/legion/extensions/microsoft_teams/cli/auth.rb', line 55 def status token_file = File.('~/.legionio/tokens/microsoft_teams.json') if File.exist?(token_file) log.info("Token file found: #{token_file}") puts 'Teams: authenticated (token file present)' else log.info('No token file found') puts 'Teams: not authenticated' end end |