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

Unable to get a token with the API using fetch/axios or Postman #35

Open
jesuismaxime opened this issue Apr 27, 2023 · 2 comments
Open

Comments

@jesuismaxime
Copy link

I don't know if it's the right place or event if this repo is maintain, but I'll give it a chance!

When trying to get a auth token (using this URL pattern; https://app.activecollab.com/XXXXXX/api/v1/issue-token), I got that response:

{
    "type": "ValueError",
    "message": "DOMDocument::loadXML(): Argument #1 ($source) must not be empty",
    "code": 0
}

I tried with fetch(), axios and Postaman, still the name result.

Here's a piece of what I am using:

        async getToken(username, password) {

            const data = {
                username,
                password,
                client_name: "...",
                client_vendor: "..."
            }

            try {
                const token = await push('/api/issue-token', data)
                this.token = token
                setToken(token)
            } catch (error) {
                console.error(error)
            }
        }

The push() method:

const push = async (route, data = {}) => {
    try {
        const config = {
            headers: {
                 'Content-Type': 'application/json',
            },
        }

        const response = await axios.post(route, data, config)

        return response.data
    } catch (error) {
        console.error(error)
    }
}

Note that the /api path is a proxy of https://app.activecollab.com/XXXX/api/v1.

@bumbus
Copy link

bumbus commented Dec 30, 2024

Same problem here, are there any solutions for that?

@bumbus
Copy link

bumbus commented Dec 30, 2024

Ok I was able to fiddle it out (for the cloud version at least).
It needs 2 requests:

  1. To https://activecollab.com/api/v1/external/login with email & password as payload, to receive an intend (not https://my.activecollab.com/api/v1/external/login)
  2. To issue-token-intent path of the tenant api url to receive the token.

Here is the Elixir snippet, but should also work with JS and others.

def get_auth_token(username, password) do
    with {:ok,
          %Req.Response{
            status: 200,
            body: %{
              "is_ok" => 1,
              "user" => %{
                "intent" => intent
              }
            }
          }} <-
           Req.new(base_url: login_url())
           |> Req.post(
             json: %{
               username: username,
               password: password
             }
           ),
         {:ok,
          %Req.Response{
            status: 200,
            body: %{
              "is_ok" => true,
              "token" => token
            }
          }} <-
           Req.new(base_url: api_url("issue-token-intent"))
           |> Req.post(
             json: %{
               client_name: @client_name,
               client_vendor: @client_vendor,
               intent: intent
             }
           ) do
      {:ok, token}
    else
      _ -> {:error, "Authentication failed"}
    end
  end

  def login_url, do: "https://activecollab.com/api/v1/external/login"
  def api_url(append \\ ""), do: Path.join([@base_url, @account_id, "api/v1", append])

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

No branches or pull requests

2 participants