当前位置: 首页>>代码示例>>C#>>正文


C# IHttpResponse.ReturnAuthRequired方法代码示例

本文整理汇总了C#中IHttpResponse.ReturnAuthRequired方法的典型用法代码示例。如果您正苦于以下问题:C# IHttpResponse.ReturnAuthRequired方法的具体用法?C# IHttpResponse.ReturnAuthRequired怎么用?C# IHttpResponse.ReturnAuthRequired使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在IHttpResponse的用法示例。


在下文中一共展示了IHttpResponse.ReturnAuthRequired方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Authorize

 public void Authorize(IHttpRequest httpRequest, IHttpResponse httpResponse, object arg3)
 {
     var apikey = httpRequest.GetBasicAuthUserAndPassword();
     bool authorized = IsAuthorized(apikey);
     if (!authorized)
     {
         httpResponse.ReturnAuthRequired();
         return;
     }
     // Don't need to do anything if a valid API key
 }
开发者ID:alexcpendleton,项目名称:Sandbox,代码行数:11,代码来源:Auth.cs

示例2: RequestFilter

        public void RequestFilter(IHttpRequest request, IHttpResponse response, object requestDto)
        {
            string Username = "";
            if (requestDto is UserRequest) {
                Username = ((UserRequest)requestDto).Username;
            } else if (requestDto is GetNotesRequest) {
                Username = ((GetNotesRequest)requestDto).Username;
            } else if (requestDto is PutNotesRequest) {
                Username = ((PutNotesRequest)requestDto).Username;
            } else {
                response.ReturnAuthRequired ();
                return;
            }

            var web_request = ((HttpListenerRequest)request.OriginalRequest).ToWebRequest ();
            IOAuthContext context = new OAuthContextBuilder ().FromWebRequest (web_request, new MemoryStream ());

            try {
                Logger.Debug ("trying to acquire authorization");
                RainyStandaloneServer.OAuth.Provider.AccessProtectedResourceRequest (context);
            } catch {
                Logger.DebugFormat ("failed to obtain authorization, oauth context is: {0}", context.Dump ());
                response.ReturnAuthRequired ();
            }

            // check if the access token matches the username
            var access_token = Rainy.RainyStandaloneServer.OAuth.AccessTokens.GetToken (context.Token);
            if (access_token.UserName != Username) {
                // forbidden
                Logger.Debug ("username does not match the one in the access token, denying");
                response.ReturnAuthRequired ();
                return;
            }
            Logger.DebugFormat ("authorization granted for user {0}", Username);

            // possible race condition but locking is to expensive
            // at this point, rather accept non-precise values
            MainClass.ServedRequests++;
        }
开发者ID:BooTeK,项目名称:Rainy,代码行数:39,代码来源:OAuthAccessFilter.cs


注:本文中的IHttpResponse.ReturnAuthRequired方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。