本文整理汇总了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
}
示例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++;
}