英文:
linkedin login returning 404 when trying to retrieve profile information
问题
我在linkedin上有一个使用登录API的应用程序。这是一个使用Go语言和goth身份验证库的Web应用程序。直到几天前,我的应用程序都能正常验证用户。现在它返回以下错误信息:
linkedin响应404,尝试获取用户信息时出错。
该应用程序已经连续运行了几周,没有进行任何更新。所以没有进行任何代码更改。
我应该提到的是,它确实将我带到了登录页面,但在输入用户名和密码后,它会重定向并输出上述错误。
goth oauth API的代码位于这里:https://github.com/markbates/goth/blob/master/providers/linkedin/linkedin.go
它基本上使用访问令牌调用以下URL:
http://api.linkedin.com/v1/people/~:(id,first-name,last-name,headline,location:(name),picture-url,email-address)
有人知道API端点是否已更改或其他导致身份验证停止工作的原因吗?
我一直在查看博客,但在API方面我没有看到任何更新,似乎也没有办法联系到linkedin开发者支持,因为它只指向stackoverflow。
英文:
I have an app on linkedin that uses the login api. It is a web app that makes use of go and the goth authentication library. Up until a few days ago my app was authenticating users fine. Now it returns this error message:
linkedin responded with a 404 trying to fetch user information
The app has been running continuously without updates for weeks. So there hasn't been any code changes.
I should mention that it does bring me to the login page but after entering my username and password it redirects and outputs the aforementioned error
The goth oauth api code is located here: https://github.com/markbates/goth/blob/master/providers/linkedin/linkedin.go
It essentially calls this url with the access token
http://api.linkedin.com/v1/people/~:(id,first-name,last-name,headline,location:(name),picture-url,email-address)
Does anyone know if the api endpoints have changed or any other reason authentication would just stop working?
I've been checking the blog but I see no updates in regards to the api and there doesn't seem to be a way to reach linkedin developer support as it just points to stackoverflow.
答案1
得分: 1
所以在深入研究这个问题之后,似乎linkedin现在从他们的API返回http 2.0响应。
我通过编写一个小的go程序,在我的本地机器上运行以及在托管服务器代码的AWS实例上运行来发现这一点。
package main
import (
"fmt"
"io/ioutil"
"net/http"
"net/http/httputil"
"net/url"
)
const (
bearerToken string = "AQVJampuUSuvWs5beuCvHiJYC--"
)
func main() {
userEndpoint := "//api.linkedin.com/v1/people/~:(id,first- name,last-name,headline,location:(name),picture-url,email-address)?format=json"
client := &http.Client{}
req, err := http.NewRequest("GET", "", nil)
req.URL = &url.URL{
Scheme: "https",
Host: "api.linkedin.com",
Opaque: userEndpoint,
}
req.Header.Set("Authorization", "Bearer "+bearerToken)
resp, err := client.Do(req)
request, _ := httputil.DumpRequest(req, true)
fmt.Println("request:", string(request))
data, _ := ioutil.ReadAll(resp.Body)
response, _ := httputil.DumpResponse(resp, false)
resp.Body.Close()
fmt.Println("response:", string(response))
fmt.Println(err, req.URL.String(), string(data))
}
在我的本地机器上运行时,API返回了包含个人资料数据的响应。当我在AWS实例上运行它时,它返回了一个带有http 2.0头的404错误。
以下是在AWS上运行此程序的输出摘录:
请求:GET https://api.linkedin.com/v1/people/~?format=json HTTP/1.1
主机:api.linkedin.com
授权:Bearer AQVJampuUSuvWs5beu--
响应:HTTP/2.0 404 Not Found
内容长度:5530
缓存控制:no-store
内容语言:en
内容类型:text/html
日期:Sat, 18 Feb 2017 03:45:21 GMT
X-Li-Pop:prod-lva1-h2
<!-- EF of static content included-->
<html>
<head>
<title>404:未找到</title>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<style type="text/css">
/* GLOBAL */
现在我不知道这是一个错误还是预期行为,但似乎linkedin在go选择时返回了http 2.0响应,导致了404错误。
我解决这个问题的方法是在go本身中关闭http 2.0客户端支持。通过设置以下环境变量:
GODEBUG=http2client=0
这样,linkedin API将返回个人资料信息。
我很想知道这是linkedin还是go的错误。希望linkedin的某个人能够发表意见。
英文:
So after digging deeper into this issue. It seems that linkedin is now returning http 2.0 responses from their api.
I discovered this by writing a small go program which I ran on my local machine and on the aws instance where the server code is located.
package main
import (
"fmt"
"io/ioutil"
"net/http"
"net/http/httputil"
"net/url"
)
const (
bearerToken string = "AQVJampuUSuvWs5beuCvHiJYC--"
)
func main() {
userEndpoint := "//api.linkedin.com/v1/people/~:(id,first- name,last-name,headline,location:(name),picture-url,email-address)?format=json"
client := &http.Client{}
req, err := http.NewRequest("GET", "", nil)
req.URL = &url.URL{
Scheme: "https",
Host: "api.linkedin.com",
Opaque: userEndpoint,
}
req.Header.Set("Authorization", "Bearer "+bearerToken)
resp, err := client.Do(req)
request, _ := httputil.DumpRequest(req, true)
fmt.Println("request:", string(request))
data, _ := ioutil.ReadAll(resp.Body)
response, _ := httputil.DumpResponse(resp, false)
resp.Body.Close()
fmt.Println("response:", string(response))
fmt.Println(err, req.URL.String(), string(data))
}
When running this on my local machine the api returned a response with the profile data. When I ran it on the aws instance it returned a 404 with an http 2.0 header
Here is an excerpt of the output of running this program on aws
request: GET https://api.linkedin.com/v1/people/~?format=json HTTP/1.1
Host: api.linkedin.com
Authorization: Bearer AQVJampuUSuvWs5beu--
response: HTTP/2.0 404 Not Found
Content-Length: 5530
Cache-Control: no-store
Content-Language: en
Content-Type: text/html
Date: Sat, 18 Feb 2017 03:45:21 GMT
X-Li-Pop: prod-lva1-h2
<!-- EF of static content included-->
<html>
<head>
<title>404: Not Found</title>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<style type="text/css">
/* GLOBAL */
Now I don't know if this a bug or expected behaviour but it appears that linkedin is returning http 2.0 responses when go is picking up causing the 404.
They way I was able to fix it was to turn off http 2.0 client support in go itself. By setting the following environment variable
GODEBUG=http2client=0
At which point the linkedin api returns the profile information.
I'm curious to know if this is a bug with linkedin or go. Hopefully someone from linkedin can chime in.
答案2
得分: 1
最近几天,我们偶尔也遇到了这些错误。
从今天开始,每个请求似乎都失败了,即使在我的本地开发机器上也是如此(生产环境是AWS)。
看起来在协议协商过程中出了问题,服务器只是放弃并返回一个标准的404响应。LinkedIn似乎不支持APLN。
我目前的解决方法是创建一个不支持HTTP/2的http.Client
,像这样:
client := &http.Client{
Transport: &http.Transport{
TLSNextProto: make(map[string]func(authority string, c *tls.Conn) http.RoundTripper),
},
}
英文:
For a few days now, we sporadically saw these errors, too.
Since today, every request seems to fail—even on my local development machine (production is AWS).
Looks like something goes wrong in the protocol negotiation process and the servers just bail out and return a standard 404 response. LinkedIn does not seem to support APLN.
My workaround right now is to create an http.Client
that does not support HTTP/2, like so:
client := &http.Client{
Transport: &http.Transport{
TLSNextProto: make(map[string]func(authority string, c *tls.Conn) http.RoundTripper),
},
}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论