新浪的oauth第一步會(huì)引導(dǎo)用戶打開一個(gè)頁(yè)面,然后用戶允許后url會(huì)重定向到網(wǎng)站根目錄下,問題是這樣的:?jiǎn)栴}一url會(huì)帶一個(gè)code參數(shù),鏈接會(huì)變成XXX.XXX.com/?code=XXXX,不使用htmlMode#$locationProvider.html5Mode(false)時(shí),route會(huì)跳轉(zhuǎn)到XXX.XXX.com/?code=XXXX#/有沒有好的辦法能取到這個(gè)code的值(現(xiàn)在用的是$window.location.search,因?yàn)?location.search在這個(gè)模式下沒能取到這個(gè)值);有沒有好的辦法把這個(gè)XXX.XXX.com/?code=XXXX#/?code=XXX去掉(不去掉的話之后每一個(gè)route跳轉(zhuǎn)的鏈接都會(huì)有)上面的這兩個(gè)問題我暫時(shí)的解決方案是用$window.location.href替換,這樣會(huì)引起整個(gè)頁(yè)面的刷新(好在是首頁(yè)登錄,還可以接受,不過總感覺應(yīng)該有更高級(jí)更angularinic的用法)測(cè)試地址http://llovebaimuda.herokuapp.com/http://llovebaimuda.herokuapp.com/#/login不用html5mode是因?yàn)槿绻苯虞斎雞rl(例如:http://llovebaimuda.herokuapp.com/phone)會(huì)導(dǎo)致404,輸入http://llovebaimuda.herokuapp.com/#/phone雖然瀏覽器顯示http://llovebaimuda.herokuapp.com/phone,但是把urlcopy給朋友的時(shí)候就會(huì)404了,除非加上#/,這個(gè)問題在angular和后端有什么好的解決方案么問題二angular有沒有辦法直接在頁(yè)面里面使用,例如新浪微博登錄的組件是個(gè)js,他會(huì)在頁(yè)面載入后對(duì)一個(gè)dom做一些處理,angular對(duì)dom的操作是在directive,然后經(jīng)過編譯-鏈接巴拉巴拉,總之就是新浪的登錄jswidget不能用,還是說angular需要特殊的處理。問題三angular中oauth又沒有比較成熟可復(fù)用的東西(中國(guó)的例如新浪微博,qq,豆瓣),https://oauth.io/這個(gè)木有微博啊oauth需要下面這幾步:1.引導(dǎo)用戶授權(quán)獲取code2.主動(dòng)向oauth的網(wǎng)站發(fā)起請(qǐng)求,獲取access_token這一步對(duì)用戶應(yīng)該是透明的,現(xiàn)在我的想法是讓頁(yè)面主動(dòng)跳轉(zhuǎn)到一個(gè)有authService的頁(yè)面中,這個(gè)authService主動(dòng)來獲取需要用到的數(shù)據(jù),然后把a(bǔ)ccess_token以及user存到$routeScope(有沒有類似backbone的localstorage?)中,這個(gè)操作無論成功與否都要跳轉(zhuǎn)到下一個(gè)頁(yè)面,這就是登錄成功才能看到的頁(yè)面if'code'ofparam_dict$window.location.href=href+'#'+DEFAULT_URLoauth到第一步的測(cè)試代碼'usestrict'https://oauth.io/STATIC_URL='/static'DEFAULT_URL='/phones'phonecatApp=angular.module('phonecatApp',['ngRoute''ConfigServices''phonecatControllers''authControllers''phonecatServices''phonecatFilters''phonecatAnimations'])phonecatApp.config(['$routeProvider''$locationProvider'($routeProvider,$locationProvider,config)->$routeProvider.when('/',{}).when('/login',{templateUrl:STATIC_URL+'/partials/auth/login.html'controller:'LoginCtrl'}).when('/auth/:code',{}).when('/phones',{templateUrl:STATIC_URL+'/partials/phone/list.html'controller:'PhoneListCtrl'}).when('/phones/:phoneId',{templateUrl:STATIC_URL+'/partials/phone/detail.html'controller:'PhoneDetailCtrl'})#Catchall.otherwise({redirectTo:'DEFAULT_URL'})#Withoutserversidesupporthtml5mustbedisabled.$locationProvider.html5Mode(false)])parse_query_dict=(query)->query=query.trim()ifquery.length$rootScope.$on('$locationChangeStart',(event,next,current)->ifnot$rootScope.userif$location.path()=='/'params=$window.location.searchifparamshref=$window.location.hrefhref=href.replace(params,'')param_dict=parse_query_dict(params)if'code'ofparam_dict$window.location.href=href+'#'+DEFAULT_URL#nologgeduser,weshouldbegoingto#loginifnext.templateUrl=="partials/login.html"#alreadygoingto#login,noredirectneededelse#notgoingto#login,weshouldredirectnow#$location.path"/login")])
angular oauth有沒有針對(duì)國(guó)內(nèi)社交玩站比較好的解決方案?
瀟湘沐
2019-04-09 20:24:57