Django linkedIn 社交认证

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

请有人帮忙,请完整阅读(我最近从不同来源尝试了很多方法)

我尝试使用“使用 LinkedIn 登录”按钮已经超过 30 天了,但没有成功.. 我只是向您展示我的代码:

我的 LinkedIn ID 和密钥(也尝试过不使用 REDIRECT_URL 行)

#MY LINKEDIN APP
SOCIAL_AUTH_LINKEDIN_OAUTH2_KEY = 'ID'
SOCIAL_AUTH_LINKEDIN_OAUTH2_SECRET = 'KEY'
REDIRECT_URI = 'http://localhost:8000/oauth/complete/linkedin-oauth2/'`


URLS
`urlpatterns = [
    path('admin/', admin.site.urls),
    path('', include('home.urls')),
    path('oauth/', include('social_django.urls', namespace='social')),
]`

LinkedIn Button
`<!--LINKEDIN BUTTON-->
        <li class="linkedin">
    <a href="{% url "social:begin" backend="linkedin-oauth2" %}">
    Sign in with Linkedin
    </a>
    </li>`

Nothing's wrong with the coding..

`INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'django.contrib.sites',
    'home',
    'social_django',

]



LOGIN_REDIRECT_URL = 'dashboard'
LOGOUT_REDIRECT_URL = 'login'
LOGIN_URL = 'login'
LOGOUT_URL = 'logout'

AUTHENTICATION_BACKENDS = (
    'django.contrib.auth.backends.ModelBackend',
    'social_core.backends.github.GithubOAuth2',
    'social_core.backends.google.GoogleOAuth2',
    'social_core.backends.linkedin.LinkedinOAuth2',


)

LinkedIn app is okay, Redicrect URI mathces as well`

`Error after Clicking Sign in with LinkedIn
Bummer, something went wrong.
In five seconds, you will be redirected to: localhost



Django error
AuthFailed at /oauth/complete/linkedin-oauth2/
Authentication failed: Scope &quot;r_liteprofile&quot; is not authorized for your application

我知道它需要

"r_liteprofile"
范围,但我在任何地方都看不到它,在 OAuth 2.0 工具中也看不到

r_liteprofile
范围错误的解决方案!

LinkedIn Authentication Error

Afterwards Django error

python django django-socialauth django-login social-authentication
1个回答
0
投票

我今天早些时候遇到了这个问题!我使用的解决方案是将

linkedin_oauth2
提供商替换为 linkedin OpenID Connect 提供商。

我将其添加到

settings.py
(以及已安装应用程序中的
allauth.socialaccount.providers.openid_connect
):

SOCIALACCOUNT_PROVIDERS = {
    "openid_connect": {
        "APPS": [
            {
                "provider_id": "linkedin-server",
                "name": "LinkedIn OIDC",
                "client_id": os.environ.get("LINKEDIN_OIDC_CLIENT_ID"),
                "secret": os.environ.get("LINKEDIN_OIDC_CLIENT_SECRET"),
                "settings": {
                    "server_url": "https://www.linkedin.com/oauth",
                },
            }
        ]
    },
}

然后,确保使用

http://localhost:8000/accounts/oidc/linkedin-server/login/callback/
作为redirect_uri。

希望有帮助!

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