解决SharePoint Online Oauth 认证非full control用户不能登录的问题
来源:互联网 发布:后台数据怎么传到前台 编辑:程序博客网 时间:2024/06/06 08:29
背景(Background)
SharePoint Online 提供一个不错的授权和认证机制, 它是基于Oauth2.0协议的。我们可以利用它来为第三方站点授权。这样我自己的网站就可以利用SharePoint的用户名密码来登录,而不用自己维护这些信息。http://msdn.microsoft.com/en-us/library/jj687470.aspx。
问题(Problem)
在利用Oauth实现认证的时候,利用上面例子中的代码,我们发现SharePoint只对管理员账号授权。也就是说尽管我只想读取sharepoint上的信息,可是他仍然要求要full control的权限。作为member拥有contributor的权限也得不到认证。
Using sharepoint Oauth example, user can not be authorized if he/she is a non-full control user.
原理
这个问题网上基本上没有资料,本人是花了一整天的时间反编译微软的代码找到的方法。下面是做认证时跳转到的OAuthAuthorizePage.aspx页面OnLoad 方法:
I spent a whole day to reflect Micorsoft's code and found following clues. Below is OnLoad method of the redirect OAuthAuthorizePage.aspx page.
protected override void OnLoad(EventArgs e) { SPUtility.EnsureAuthentication(); this.ValidateRequest(); SPSecurity.SuppressAccessDeniedRedirectInScope scope = new SPSecurity.SuppressAccessDeniedRedirectInScope(); try { if (!base.get_Web().DoesUserHavePermissions(this.get_RightsRequired())) { throw new UnauthorizedAccessException(); } base.OnLoad(e); } catch (UnauthorizedAccessException) { this.RedirectWithError("access_denied", null); } finally { if (scope != null) { scope.Dispose(); } } }
关键点就在RightsRequired这个属性,而这个属性是这样写的(The key point is RightsRequired, here is the property):
protected override SPBasePermissions RightsRequired{ get { if (string.IsNullOrEmpty(base.Request.QueryString["scope"])) { return (base.get_RightsRequired() | (SPBasePermissions.EmptyMask | SPBasePermissions.ViewFormPages)); } return (base.get_RightsRequired() | SPBasePermissions.ManagePermissions); }}
也就是说,如果你如例子中这样写下面这句(As you see, it needs ManagePermissions if you simpliy copy the below line from the reference article)
Response.Redirect(TokenHelper.GetAuthorizationUrl(sharePointSiteUrl.ToString(), "Web.Write"));
只要scope参数不为空(“”),那么就需要ManagePermissions(管理权限)。
解决方法
所以说在redirect的时候我们只需要写成下面这样(scope设置为空),只需要有View权限的用户就可以通过认证了。(The issue can be resovled once you change the scope parameter toempty.)
Response.Redirect(TokenHelper.GetAuthorizationUrl(sharePointSiteUrl.ToString(), ""));
- 解决SharePoint Online Oauth 认证非full control用户不能登录的问题
- 解决非root用户不能在主机上登录的问题
- iphone开发我的新浪微博客户端-用户登录OAuth授权认证篇(1.3)
- iphone开发我的新浪微博客户端-用户登录OAuth授权认证篇(1.3)
- useradd 用户不能登录图形界面的问题
- 如何解决fedora 13中root用户不能登录的问题
- 如何解决fedora 13中root用户不能登录的问题
- 如何解决fedora 13中root用户不能登录的问题
- 解决不能登录Chrome的问题
- 解决StackOverFlow不能登录的问题
- 解决忘记用户登录密码的问题
- 解决QQ登录SDK不能网页授权登录的问题
- 解决ios的https双向认证不能抓包问题
- 解决 SharePoint 2013 管理中心登录问题。
- mysql非本机不能登录的问题
- OAuth认证的过程
- 关于sqlplus 新创建的用户不能登录的问题。
- 解决swift非admin用户不能访问
- android源码2.3编译—致命错误: bits/predefs.h
- Minimum Path Sum
- 多选按钮的实例
- Jquery(智能感知AJAX,从后台调数据)
- 黑马程序员-java基础_线程与单例
- 解决SharePoint Online Oauth 认证非full control用户不能登录的问题
- HDU 12O3 I NEED A OFFER!
- Codeforces Round #187 DIV 1
- 黑马程序员-java基础加强_jdk1.6与1.7
- SDK & MFC & 消息分类小结
- 创建链接服务器
- Android SDK4.2 (API17) 开发环境的搭建
- 格式化数字
- windows批处理命令大全