I am using the allauth module to authenticate users with Google.
In the template /accounts/login/
provided by allauth, there is a link "google
" that directs to
href="/accounts/google/login/?process=login"
. Clicking on this link will authenticate the user with Google.
In my own custom template, I have included the same exact link:
<a id="google-login" href="/accounts/google/login/?process=login">Google</a>
However, when I click on this link in my template, I encounter an error:
`XMLHttpRequest cannot load https://accounts.google.com/o/oauth2/auth?state=************&response_type=…id=*************************. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://127.0.0.1' is therefore not allowed access.`
I am baffled as to why the identical link works perfectly fine in the allauth template (/accouts/login/) but not in my own template. The links have the same href attribute.
Upon further investigation, I noticed a key difference between clicking the link from the console vs from the HTML page: (my request vs allauth's request)
Accept:text/html, */*; q=0.01
Accept:text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
Referer:http://localhost:8000/static/index.html
Referer:http://localhost:8000/accounts/login/
X-Requested-With:XMLHttpRequest
This line is missing in the request from allauth's HTML page.
If anyone has any suggestions or solutions, please share them with me.
Thank you in advance.
Jenia