简体   繁体   English

如何在没有弹出窗口的情况下实现 React Apple 登录

[英]How to implement a React Apple sign-in without a popup

I have been working in react web app where I have a SIWA button.我一直在 React web 应用程序中工作,我有一个 SIWA 按钮。 Due to some campatability issues, I could not use popup for siginin, so I rather implemented redirecting user to a seperate apple's signin page, and after sucessful siginin apple would redirect user back to my webapp.由于一些兼容性问题,我无法使用 siginin 的弹出窗口,所以我宁愿实现将用户重定向到单独的苹果登录页面,并且在成功的 siginin 苹果将用户重定向回我的 webapp。 I had set the response type to fragments , so that apple would add the id_token to the url itself when redirectring, which I could then use in my own webapp.我已经将响应类型设置为fragments ,这样苹果会在重定向时将id_token添加到 url 本身,然后我可以在我自己的 webapp 中使用它。

This approach was working fine till now because I hadn't added email or name to the scope for SIWA.到目前为止,这种方法运行良好,因为我没有为 SIWA 添加 email 或名称到 scope。 But now I had to add them both, so that I would be able to retrieve them later using the id_token .但现在我必须同时添加它们,这样我以后就可以使用id_token检索它们。 But it seems apple doesnot allow adding scopes without setting the responseType to form_post .但似乎苹果不允许在不将responseType设置为form_post的情况下添加范围。 If I am not wrong, I am supposed to create a POST endpoint in my backend which will accept the given form_post data.如果我没记错的话,我应该在我的后端创建一个POST端点,它将接受给定的form_post数据。 But if I did so, how will I be able to redirect user back to my frontend, since the redirect url for SIWA would have to be set to the backend's endpoint?但是如果我这样做了,我将如何能够将用户重定向回我的前端,因为必须将 SIWA 的重定向 url 设置为后端的端点?

Bascially, my requirements are, I should be able to redirect user back to the frontend after successful login, and the frontend should also get the id_token .基本上,我的要求是,我应该能够在成功登录后将用户重定向回前端,并且前端也应该获得id_token It doesn't matter if that involves my backend or not.这是否涉及我的后端并不重要。 And also its very important that I do so without using the popup signin.而且在不使用弹出登录的情况下执行此操作也非常重要。

Thanks for any help in advance.感谢您提前提供帮助。

Just make the POST endpoint return a 302 status and a Location header of your front end URL.只需让 POST 端点返回 302 状态和前端 URL 的Location header。

https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/302https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/302

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM