You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Angular 15集成LinkedIn登录:换取access token时出现404错误

Angular 15集成LinkedIn登录换取AccessToken时返回404问题

我正在Angular 15应用中集成LinkedIn登录功能,Google、Microsoft和Facebook的登录已经完成且运行正常。

我已在LinkedIn平台配置并验证应用,添加了「Sign In with LinkedIn using OpenID Connect」产品。目前能成功将用户重定向至以下登录URL:

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中获取code后,调用以下接口换取access token时,始终返回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 });
}

内容的提问来源于stack exchange,提问作者Alex

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.25 08:12:35