我正在使用Django作为后端,Angular作为前端创建Web应用程序。
Angular运行在Yeoman栈上的localhost:9000上,而Django运行在localhost:8000上。我使用grunt-contrib-proxy将所有的$http调用从Angular重定向到Django端口的/api。例如,如果Angular请求localhost:9000/api/hello,则会重定向到localhost:8000/api/hello,并由Django提供服务。
我计划设置Django Rest Framework来为所有Angular请求提供/api路径服务。
到目前为止一切都好。
现在,我已经配置好并且正在工作的Django-allauth安装用于进行Oauth身份验证到第三方服务。它在使用纯旧版Django时有效,但我不知道如何与Angular一起使用。
唯一想到的事情是通过django rest framework提供allauth视图,但是身份验证后的重定向怎么办?我无法理解。
是最好放弃这种方法,直接从前端(Angular)进行Oauth身份验证吗?
编辑: 我成功地从Angular调用了登录视图。
Angular运行在Yeoman栈上的localhost:9000上,而Django运行在localhost:8000上。我使用grunt-contrib-proxy将所有的$http调用从Angular重定向到Django端口的/api。例如,如果Angular请求localhost:9000/api/hello,则会重定向到localhost:8000/api/hello,并由Django提供服务。
我计划设置Django Rest Framework来为所有Angular请求提供/api路径服务。
到目前为止一切都好。
现在,我已经配置好并且正在工作的Django-allauth安装用于进行Oauth身份验证到第三方服务。它在使用纯旧版Django时有效,但我不知道如何与Angular一起使用。
唯一想到的事情是通过django rest framework提供allauth视图,但是身份验证后的重定向怎么办?我无法理解。
是最好放弃这种方法,直接从前端(Angular)进行Oauth身份验证吗?
编辑: 我成功地从Angular调用了登录视图。
In grunt-contrib-proxy I've added the account context and rewrite rule:
context: ['/api', '/accounts'], rewrite: { '^/api': '/api', '^/account': '/accounts' }
I've made an ajax call from angular, asking for the allaluth login view (for example for github):
$http.get('/accounts/github/login/?process=login')
XMLHttpRequest cannot load https://github.com/login/oauth/authorize?scope=&state=BlaBla&redirect…ub%2Flogin%2Fcallback%2F&response_type=code&client_id=BlaBlaBla. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:9000' is therefore not allowed access. (index):1
(这里的BlaBla是我的补充说明)。我认为我在做某件完全错误的事情。