django-allauth重定向确认页面

huangapple go评论63阅读模式
英文:

django-allauth redirect confirm page

问题

在DJango上,我有一个应用程序。在登录部分,我已经使用DJango allauth实现了与Microsoft的身份验证。当我点击"登录"按钮与Microsoft登录时,会在重定向到Microsoft之前,将我重定向到一个页面,我必须点击"继续"按钮。我想要移除这个第二个页面,使其自动将我重定向到Microsoft页面。
我在我的"settings.py"文件中有以下内容:

SOCIALACCOUNT_PROVIDERS = {
    'microsoft': {
        'APP': {
            'client_id': '',
            'secret': '',
        },
        'SCOPE': ['User.Read'],
        'AUTH_PARAMS': {
            'prompt': 'select_account',
        },
        'INIT_PARAMS': {
            'prompt': 'select_account',
        },
        'callback_url': 'https://myapp.test.com/accounts/microsoft/login/callback/',
    },
}
ACCOUNT_EMAIL_VERIFICATION = 'None'
ACCOUNT_EMAIL_REQUIRED = False

我不知道应该做什么更改。

英文:

I have an app on DJango. In the login part I have implemented authentication with Microsoft using DJango allatuh. When I press the "sign in" button with microsoft, before redirecting to the microsof, it redirects me to a page where I have to press the "continue" button. I want to remove this second page so that it automatically redirects me to the microsoft page.
I have this on my "settings.py" file:

SOCIALACCOUNT_PROVIDERS = {
    'microsoft': {
        'APP': {
            'client_id': '',
            'secret': '',
        },
        'SCOPE': ['User.Read'],
        'AUTH_PARAMS': {
            'prompt': 'select_account',
        },
        'INIT_PARAMS': {
            'prompt': 'select_account',
        },
        'callback_url': 'https://myapp.test.com/accounts/microsoft/login/callback/',
    },
}
ACCOUNT_EMAIL_VERIFICATION = 'None'
ACCOUNT_EMAIL_REQUIRED = False

I don't know what to change

答案1

得分: 0

你可以使用以下代码来绕过确认页面:

<form method="post" action="{% url 'microsoft_login' %}">
    {% csrf_token %}
    <button type="submit" class="btn">
        使用Microsoft登录
    </button>
</form>

而不是:

{% provider_login_url 'microsoft' %}
英文:

You can use this code for bypass that confirmation page:

&lt;form method=&quot;post&quot; action=&quot;{% url &#39;microsoft_login&#39; %}&quot;&gt;
            {% csrf_token %}
            &lt;button type=&quot;submit&quot; class=&quot;btn&quot;&gt;
             Login with Microsoft
            &lt;/button&gt;
&lt;/form&gt;

instead of:

 {% provider_login_url &#39;microsoft&#39; %}

答案2

得分: 0

代替 &#39;prompt&#39;: &#39;select_account&#39;,你可以使用 &#39;prompt&#39;: &#39;none&#39;

SOCIALACCOUNT_PROVIDERS = {
    &#39;microsoft&#39;: {
        &#39;APP&#39;: {
            &#39;client_id&#39;: &#39;&#39;,
            &#39;secret&#39;: &#39;&#39;,
        },
        &#39;SCOPE&#39;: [&#39;User.Read&#39;],
        &#39;AUTH_PARAMS&#39;: {
            &#39;prompt&#39;: &#39;none&#39;,
        },
        &#39;INIT_PARAMS&#39;: {
            &#39;prompt&#39;: &#39;none&#39;,
        },
        &#39;callback_url&#39;: &#39;https://myapp.test.com/accounts/microsoft/login/callback/&#39;,
    },
}
ACCOUNT_EMAIL_VERIFICATION = &#39;None&#39;
ACCOUNT_EMAIL_REQUIRED = False
英文:

Instead of &#39;prompt&#39;: &#39;select_account&#39;, you could use &#39;prompt&#39;: &#39;none&#39;

SOCIALACCOUNT_PROVIDERS = {
    &#39;microsoft&#39;: {
        &#39;APP&#39;: {
            &#39;client_id&#39;: &#39;&#39;,
            &#39;secret&#39;: &#39;&#39;,
        },
        &#39;SCOPE&#39;: [&#39;User.Read&#39;],
        &#39;AUTH_PARAMS&#39;: {
            &#39;prompt&#39;: &#39;none&#39;,
        },
        &#39;INIT_PARAMS&#39;: {
            &#39;prompt&#39;: &#39;none&#39;,
        },
        &#39;callback_url&#39;: &#39;https://myapp.test.com/accounts/microsoft/login/callback/&#39;,
    },
}
ACCOUNT_EMAIL_VERIFICATION = &#39;None&#39;
ACCOUNT_EMAIL_REQUIRED = False

huangapple
  • 本文由 发表于 2023年5月26日 16:30:58
  • 转载请务必保留本文链接:https://go.coder-hub.com/76339037.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定