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

rest api 302 Temporary Redirect #119

Open
fullky opened this issue Oct 8, 2021 · 4 comments
Open

rest api 302 Temporary Redirect #119

fullky opened this issue Oct 8, 2021 · 4 comments
Labels
question Further information is requested

Comments

@fullky
Copy link

fullky commented Oct 8, 2021

I have a problem with…
After I pass "api_key" as a parameter, I report an error of "302 temporary redirection". After I write "open_access" in the configuration file, I do not pass "api_key", but I also report the same error of temporary redirection. There is no configuration about redirection in my configuration file. How should I solve it? Thank you very much
Details (please complete the following information):

  • Tigase version: [e.g. 8.1.2]
  • JVM flavour and version [OpenJDK11]
  • Operating system/distribution/version [Linux centos7]
@fullky fullky added the question Further information is requested label Oct 8, 2021
@hantu85
Copy link
Contributor

hantu85 commented Oct 8, 2021

Tigase XMPP Server does not support api_key but only api-key parameter

@fullky
Copy link
Author

fullky commented Oct 8, 2021

Tigase XMPP服务器不支持api_key,但只有api-key参数

How do I use it?

This is my code, error reported 302 temporary redirection

        HttpClient client = new DefaultHttpClient();
        HttpPost  post = new HttpPost("https://im.aeeago.com:8080/rest/stream");
        String sendString ="<message xmlns=\"jabber:client\" type=\"chat\"  to=\"[email protected]\"><body>{\"type\":1,\"msgid\":\"dsf\",\"content\":\"test\"} </body></message>";
        System.out.println(sendString);
        StringEntity entity = new StringEntity(sendString,"utf-8");
        entity.setContentType("application/xml");
        entity.setContentEncoding("utf-8");
        post.setEntity(entity);
        HttpResponse response= null;
        try {
            response = client.execute(post);
        } catch (IOException e) {
            e.printStackTrace();
        }```

@fullky
Copy link
Author

fullky commented Oct 8, 2021

Tigase XMPP服务器不支持api_key,但只有api-key参数

What should I do with "each request needs to be authorized by sending a valid administrator JID and password as user and password of BASIC HTTP authorization method." in the document? The error I am reporting is 403 Forbidden,
image

@woj-tek
Copy link
Contributor

woj-tek commented Oct 8, 2021

In order to make HTTP request you need to:

  1. pass api-key (configured in HTTP api key repository via admin web ui)
  2. authenticate the request using HTTP Basic access authentication. You can find how to do that using search engine: duckduckgo: java httpclient basic auth, eg.:
val httpClient: HttpClient = HttpClient.newBuilder()
            .connectTimeout(Duration.ofSeconds(10))
            .authenticator(object : Authenticator() {   
                override fun getPasswordAuthentication(): PasswordAuthentication {
                    return PasswordAuthentication("admin", "password".toCharArray())
                }
            })
            .version(HttpClient.Version.HTTP_1_1)
            .build()

    val request = HttpRequest.newBuilder()
            .GET()
            .uri(URI.create("https://im.aeeago.com:8080/rest/stream"))
            .build()

    val httpResponse = httpClient.send(request, BodyHandlers.ofString())
    println("httpResponse statusCode = ${httpResponse.statusCode()}")
    println(httpResponse.body())

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

No branches or pull requests

3 participants