Versão atual:

Erro na autenticação Oauth 1.0 ao solicitar token

Olá a todos,

Estou tentando acessar o Fluig via OAuth 1.0 para consumir servicos REST, mas estou esbarrando na autenticação. Do lado do Fluig, foi criada a aplicação para permitir o consumo dos serviços REST, gerando as chaves "Consumer key" e "Consumer Secret". O problema ocorre quando minha aplicação solicita um token. O Fluig server é acessado via https, como as chamadas OAuth são via http, acredito que seja algum problema relativo aos redirecionamentos internos no servidor, como sugere o segundo exemplo que postei logo abaixo.

Segui este exemplo aqui: TesteClient

E ao fazer as devidas configurações, tenho esta exceção:

oauth.signpost.exception.OAuthCommunicationException: Communication with the service provider failed: Server returned HTTP response code: 411 for URL: http://portal.myfluig.com.br:80/portal/api/rest/oauth/request_token
    at oauth.signpost.AbstractOAuthProvider.retrieveToken(AbstractOAuthProvider.java:214)
    at oauth.signpost.AbstractOAuthProvider.retrieveRequestToken(AbstractOAuthProvider.java:69)
    at com.fluig.oauth.OAuthClient.loginFluig(OAuthClient.java:109)
    at com.fluig.oauth.OAuthClient.prepareResources(OAuthClient.java:99)
    at br.com.myfluig.fluig.br.com.myfluig.fluig.oauth.TestClient.test(TestClient.java:49)
    at br.com.myfluig.fluig.br.com.myfluig.fluig.oauth.TestClient.main(TestClient.java:36)
Caused by: java.io.IOException: Server returned HTTP response code: 411 for URL: http://portal.myfluig.com.br:80/portal/api/rest/oauth/request_token
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
    at sun.net.www.protocol.http.HttpURLConnection$10.run(HttpURLConnection.java:1926)
    at sun.net.www.protocol.http.HttpURLConnection$10.run(HttpURLConnection.java:1921)
    at java.security.AccessController.doPrivileged(Native Method)
    at sun.net.www.protocol.http.HttpURLConnection.getChainedException(HttpURLConnection.java:1920)
    at sun.net.www.protocol.http.HttpURLConnection.getInputStream0(HttpURLConnection.java:1490)
    at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1474)
    at oauth.signpost.basic.HttpURLConnectionResponseAdapter.getContent(HttpURLConnectionResponseAdapter.java:18)
    at oauth.signpost.AbstractOAuthProvider.handleUnexpectedResponse(AbstractOAuthProvider.java:228)
    at oauth.signpost.AbstractOAuthProvider.retrieveToken(AbstractOAuthProvider.java:189)
    ... 5 more
Caused by: java.io.IOException: Server returned HTTP response code: 411 for URL: http://portal.myfluig.com.br:80/portal/api/rest/oauth/request_token
    at sun.net.www.protocol.http.HttpURLConnection.getInputStream0(HttpURLConnection.java:1876)
    at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1474)
    at java.net.HttpURLConnection.getResponseCode(HttpURLConnection.java:480)
    at oauth.signpost.basic.HttpURLConnectionResponseAdapter.getStatusCode(HttpURLConnectionResponseAdapter.java:22)
    at oauth.signpost.AbstractOAuthProvider.retrieveToken(AbstractOAuthProvider.java:178)
    ... 5 more

Tambem fiz uma chamada baseada neste exemplo: Fluig api e obtive um mensagem um pouco mais detalhada que sugere algum problema no redirecionamento da chamada http para perdir um token.

net.oauth.OAuthException: 
HTTP/1.1 302 Redirect
Content-Type: text/html; charset=UTF-8
Location: https://portal.myfluig.com.br/portal/api/rest/oauth/request_token
Server: Microsoft-IIS/7.5
X-Powered-By: ASP.NET
Date: Thu, 27 Jul 2017 14:30:09 GMT
Content-Length: 188

<head><title>Document Moved</title></head>
<body><h1>Object Moved</h1>This document may be found <a HREF="https://portal.myfluig.com.br/portal/api/rest/oauth/request_token">here</a></body>
    at com.fluig.api.client.env.DesktopClient.access(DesktopClient.java:166)
    at com.fluig.api.client.env.FluigClient.get(FluigClient.java:42)
    at br.com.myfluig.fluig.br.com.myfluig.fluig.oauth.FluigClientExample.main(FluigClientExample.java:38)
Caused by: net.oauth.OAuthProblemException: HTTP/1.1 302 Redirect
URL: http://portal.myfluig.com.br:80/portal/api/rest/oauth/request_token?oauth_callback=http%3A%2F%2Flocalhost%3A65532%2Foauth%2Fcallback&oauth_consumer_key=EAPX&oauth_signature_method=HMAC-SHA1&oauth_timestamp=1501165809&oauth_nonce=521180768775396&oauth_version=1.0&oauth_signature=5QSaZr7Nlx4efpAGGZK7fo7R7PU%3D
oauth_signature base string: GET&http%3A%2F%2Fportal.myfluig.com.br%2Fportal%2Fapi%2Frest%2Foauth%2Frequest_token&oauth_callback%3Dhttp%253A%252F%252Flocalhost%253A65532%252Foauth%252Fcallback%26oauth_consumer_key%3DEAPX%26oauth_nonce%3D521180768775396%26oauth_signature_method%3DHMAC-SHA1%26oauth_timestamp%3D1501165809%26oauth_version%3D1.0
>>>>>>>> HTTP request:
GET /portal/api/rest/oauth/request_token?oauth_callback=http://localhost:65532/oauth/callback&oauth_consumer_key=EAPX&oauth_signature_method=HMAC-SHA1&oauth_timestamp=1501165809&oauth_nonce=521180768775396&oauth_version=1.0&oauth_signature=5QSaZr7Nlx4efpAGGZK7fo7R7PU=


<<<<<<<< HTTP response:
HTTP/1.1 302 Redirect
Content-Type: text/html; charset=UTF-8
Location: https://portal.myfluig.com.br/portal/api/rest/oauth/request_token
Server: Microsoft-IIS/7.5
X-Powered-By: ASP.NET
Date: Thu, 27 Jul 2017 14:30:09 GMT
Content-Length: 188

<head><title>Document Moved</title></head>
<body><h1>Object Moved</h1>This document may be found <a HREF="https://portal.myfluig.com.br/portal/api/rest/oauth/request_token">here</a></body>
    at net.oauth.client.OAuthResponseMessage.toOAuthProblemException(OAuthResponseMessage.java:83)
    at net.oauth.client.OAuthClient.invoke(OAuthClient.java:308)
    at net.oauth.client.OAuthClient.invoke(OAuthClient.java:262)
    at net.oauth.client.OAuthClient.getRequestTokenResponse(OAuthClient.java:192)
    at com.fluig.api.client.env.DesktopClient.access(DesktopClient.java:112)
    ... 2 more

Versões (3):

Ver a versão formatada

Erro na atenticação Oauth 1.0 ao solicitar o token

Comentário

new question