Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No valid auth strategy detected #188

Open
h0pes opened this issue Jan 10, 2024 · 9 comments
Open

No valid auth strategy detected #188

h0pes opened this issue Jan 10, 2024 · 9 comments

Comments

@h0pes
Copy link

h0pes commented Jan 10, 2024

Hi,
first of all thank you very much for developing this plugin!
Sourcegraph is a game changer. I love it.

I get the No valid auth strategy detected error upon running :checkhealth sg, despite running (apparently fine) the SourcegraphLogin command.

This is the full output of the :checkhealth sg command:

sg: require("sg.health").check()

sg.nvim report ~
- Machine: x86_64, sysname: Linux
- OK Valid nvim version: table: 0x7f50b3ad9398
- OK Found `cargo` (cargo 1.74.1 (ecb9851af 2023-10-18)) is executable
-     Use `:SourcegraphDownloadBinaries` to avoid building locally.
- OK Found `sg-nvim-agent`: "/home/marco/.local/share/nvim/lazy/sg.nvim/dist/sg-nvim-agent"
- OK Found `node` (config.node_executable) is executable.
  Version: '18.18.2'
- OK Found `cody-agent`: /home/marco/.local/share/nvim/lazy/sg.nvim/dist/cody-agent.js
- ERROR No valid auth strategy detected. See ':help |sg'| for more info.
- ERROR Cannot check Cody Status, not logged in
- ERROR sg.nvim has issues that need to be resolved

When I run :SourcegraphLogin, I confirm the endpoint url as https://sourcegraph.com/, upon hitting <CR>, a browser TAB opens with the following url:
https://sourcegraph.com/users/h0pes/settings/tokens/new/callback?requestFrom=NEOVIM-52068.

I click Confirm on the form button. A new tab is opened with this url:
http://localhost:52068/api/sourcegraph/token?token=sgp_[redacted]_[redacted] and the message:
Credentials have been saved to Neovim. Restart Neovim now..

If I restart Neovim, I experience the same behavior as not logged in per checkhealth.

I'm authenticated on my browser session to https://sourcegraph.com, if that matters.

If I run :SourcegraphLogin! and I paste the access token created in nvim command bar, after having confirmed the endpoint, no errors or messages appear.
I can see the personal access token under just created under the Settings page in Sourcegraph.

This is my config:

{
    "sourcegraph/sg.nvim",

    dependencies = { "nvim-lua/plenary.nvim" },

    config = function(_, opts)
      require("sg").setup(opts)
      status.cody = true
    end,

    opts = require("custom.configs.sg").opts,
    keys = require("custom.configs.sg").keys,
  },
local M = {}
M.opts = {
  -- ... other configuration options ...

  -- Disable LSP suggestions
  on_attach = function(client)
    local buffer_name = vim.fn.expand "%:t"
    if buffer_name ~= "COMMIT_EDITMSG" then
      if client.supports_method "textDocument/formatting" then
        vim.api.nvim_clear_autocmds { group = augroup, buffer = bufnr }
        vim.api.nvim_create_autocmd("BufWritePre", {
          group = augroup,
          buffer = bufnr,
          callback = function()
            vim.lsp.buf.format { bufnr = bufnr }
          end,
        })
      end

      if client.resolved_capabilities.document_highlight then
        vim.api.nvim_exec(
          [[
        augroup lsp_document_highlight
        autocmd! * <buffer>
        autocmd CursorHold <buffer> lua vim.lsp.buf.document_highlight()
        autocmd CursorMoved <buffer> lua vim.lsp.buf.clear_references()
        augroup END
      ]],
          false
        )
      end
    end
  end,
}

M.keys = {

  {
    "<leader>ai",
    ":CodyChat<CR>",
    mode = "n",
    desc = "AI Assistant",
  },

  {
    "<leader>ad",
    function()
      local line = vim.fn.getline "."
      local start = vim.fn.col "."
      local finish = vim.fn.col "$"
      local text = line:sub(start, finish)
      vim.fn.setreg('"', text)
      vim.cmd [[CodyTask 'Write document for current context']]
    end,
    mode = "n",
    desc = "Generate Document with AI",
  },

-- some other custom keymaps...
return M

I attach some screens.

NVIM v0.9.4
Build type: Release
LuaJIT 2.1.1702233742

2024-01-10_17-16_SourcegraphLogin_4

2024-01-10_17-16_SourcegraphLogin_1

2024-01-10_17-16_SourcegraphLogin_2

2024-01-10_17-16_SourcegraphLogin_3

@h0pes
Copy link
Author

h0pes commented Jan 11, 2024

I've been able to get a green check on :checkhealth sg after using the src binary from Sourcegraph and authenticating setting the SRC_ENDPOINT and SRC_ACCESS_TOKEN env variables.
I still would like to know why the SourcegraphLogin command was not working though...

@tjdevries
Copy link
Collaborator

Do you happen to be on Arch? Or rather, what's your distro?

The way that I'm storing the access tokens in Rust uses some system libraries that may not be available by default (so I may have to pursue a different strategy, or find some other way to store if the configuration doesn't work)

@h0pes
Copy link
Author

h0pes commented Jan 12, 2024

Hi, thanks for the reply.
Yes, I'm on Arch 😊

One thing I noticed is that I don't get an sg_token in my plenary cache dir (plenary installed, loaded and writable by neovim). Anyway, even manually setting the cache token file, makes no difference.

Let me know if I can help you to investigate it more.
Thanks a lot for your help.

@tjdevries
Copy link
Collaborator

Ah, I figure out something that was definitely a problem on my side. I was not passing the error from attempting to save the credentials to the user -- can you try doing it again? Hopefully this time it surfaces an error to you (or works haha)

@h0pes
Copy link
Author

h0pes commented Jan 13, 2024

Hi, I updated the plugin to the latest version which includes this commit, but nothing seems to have changed.
:SourcegraphLogin successfully completes its tasks, I get the

Credentials have been saved to Neovim. Restart Neovim now.

message in my browser tab and inspecting the Access tokens section of my sourcegraph.com profile, I can find the newly created token.
I then restart neovim, running :checkhealth sg still shows the same error.
Trying to manually input the endpoint and token with :SourcegraphLogin! seems to work fine, I mean no errors nor notifications are shown, but still showing as not authenticated (in fact CodyChat and other commands tell me I'm not authenticated).

@pmizio
Copy link

pmizio commented Jan 16, 2024

I can confirm same error on MacOS, I cannot authenticate using SourcegraphLogin nor token saved in env variable.

@safvan-husain
Copy link

I also have this issue on WSL, I cannot authenticate using SourcegraphLogin nor token saved in env variable.

@CompeyDev
Copy link

Same error on WSL, oof.

@luisdavim
Copy link

I have the same issue on Termux, to solve It I've set the SRC_ENDPOINT and SRC_ACCESS_TOKEN env variables on a file that I source on my shell profile.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

9 participants