与角JS删除Facebook的OAuth的哈希 [英] Remove Facebook OAuth hash with Angular JS

查看:112
本文介绍了与角JS删除Facebook的OAuth的哈希的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Facebook的喜欢#_ = _ 添加到我们给它的OAuth回调URL的末尾。虽然我们没有使用基于散列的导航,它看起来讨厌,我想摆脱它。

Facebook likes to add #_=_ to the end of the OAuth callback URL we give it. While we're not using hash-based navigation, it looks annoying and I'd like to get rid of it.

的location.hash =''; 导致一个无限循环中的 $观看(这也与<$发生C $ C> $ window.location.hash =''; )。 $的location.hash('')的角方式; 改变不了什么。 $ location.path(''); 会让我们的方式的一部分出现,导致 /#/ 被追加我们的网址。

location.hash = ''; causes an infinite loop in $watch (this also happens with $window.location.hash = '';). The Angular way of $location.hash(''); changes nothing. $location.path(''); gets us part of the way there, resulting in /#/ being appended to our url.

我也用 $ locationProvider.html5Mode 发挥各地,并获得什么,但错误。 (错误:[$喷油器:unpr]未知提供商:$ locationProviderProvider&LT; - $ locationProvider
),尽​​管这可能是我自己的错。

I've also played around with $locationProvider.html5Mode and received nothing but errors. (Error: [$injector:unpr] Unknown provider: $locationProviderProvider <- $locationProvider ) though this may be my own fault.

如何删除没有错误的OAuth的哈希?

How can I remove the OAuth hash without error?

推荐答案

我有FB没有经验,但我们采用了棱角分明的HTTP的拦截的。你可以实现一个简单的正则表达式的输入数据代替这种方式(改编自文档):

I have no experience with FB, but we do a fair amount of URL processing using Angular's http interceptors. You can implement a simple regex replace on incoming data this way (adapted from the docs):

// register the interceptor as a service
$provide.factory('myHttpInterceptor', function($q, dependency1, dependency2) {
    return {
        'response': function(response) {
            // alter the response
            var loc = response.headers.location;
            response.headers.location = loc.replace(/#_=_$/,'');

            // pass along the altered response
            return response;
        }
    };
});
$httpProvider.interceptors.push('myHttpInterceptor');

这正好在你的角度应用的的.config 模块。它会通过$ http服务的所有请求下透明地运行,所以你可能想,如果你需要独自离开某些URL做其他处理。

This goes in a .config module of your angular app. It will run transparently under ALL requests via the $http service, so you may want to do additional processing if you need to leave some URLs alone.

这篇关于与角JS删除Facebook的OAuth的哈希的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆