用户认证后调用linkedin API获取访问令牌时出现404错误

问题描述 投票:0回答:1

我正在尝试在我的 Angular 15 应用程序中设置使用 linkedin 登录(谷歌、微软和 Facebook 已完成并正在运行)。

我使用以下产品在 linkedin 中配置和验证了我的应用程序:

使用 OpenID Connect 登录 LinkedIn

我成功重定向用户以通过以下网址登录:

private redirectUri = 'https://localhost:44319/';
private linkedInAuthScope = 'openid profile email'
private clientId = 'MYID'
private clientSecret = 'MYSECRET'
private linkedInAuthUrl = `https://www.linkedin.com/oauth/v2/authorization?response_type=code&client_id=${this.clientId}&redirect_uri=${encodeURIComponent(this.redirectUri)}&scope=${encodeURIComponent(this.linkedInAuthScope)}&state=asdfasdfas`;

这可以工作并使用网址中的“code”和“state”参数重定向回我的应用程序。我从 url 中获取代码并进行以下调用以将代码交换为访问令牌。但它总是返回 404 错误。

getAccessToken(code: string): Observable<any> {
    
    const url = 'https://www.linkedin.com/oauth/v2/accessToken';

    const body = new HttpParams()
        .set('grant_type', 'authorization_code')
        .set('code', code)
        .set('client_id', this.clientId)
        .set('client_secret', this.clientSecret)
        .set('redirect_uri', this.redirectUri)

    const headers = new HttpHeaders().set('Content-Type', 'application/x-www-form-urlencoded');

    return this.http.post<any>(
        url,
        body,
        { headers });
}
angular oauth-2.0 linkedin-api
1个回答
0
投票

它表明您无法从浏览器调用https://www.linkedin.com/oauth/v2/accessToken。必须从后端完成。没有文档说明这一点。

© www.soinside.com 2019 - 2024. All rights reserved.