GetAuthorizationToken() public method

public GetAuthorizationToken ( ) : string
return string
Ejemplo n.º 1
0
 private async Task OnProcess(IDictionary<string, object> owinenv)
 {
   var env = new OWINEnv(owinenv);
   var cancel_token = env.CallCanlelled;
   try {
     if (!HTTPUtils.CheckAuthorization(env.GetAuthorizationToken(), env.AccessControlInfo)) {
       throw new HTTPError(HttpStatusCode.Unauthorized);
     }
     if (env.RequestMethod!="HEAD" && env.RequestMethod!="GET") {
       throw new HTTPError(HttpStatusCode.MethodNotAllowed);
     }
     var query = env.RequestParameters;
     string value;
     if (query.TryGetValue("cmd", out value)) {
       switch (value) {
       case "viewxml": //リレー情報XML出力
         await OnViewXML(env, query, cancel_token);
         break;
       case "stop": //チャンネル停止
         await OnStop(env, query, cancel_token);
         break;
       case "bump": //チャンネル再接続
         await OnBump(env, query, cancel_token);
         break;
       default:
         throw new HTTPError(HttpStatusCode.BadRequest);
       }
     }
     else {
       throw new HTTPError(HttpStatusCode.BadRequest);
     }
   }
   catch (HTTPError err) {
     env.ResponseStatusCode = (int)err.StatusCode;
   }
   catch (UnauthorizedAccessException) {
     env.ResponseStatusCode = (int)HttpStatusCode.Forbidden;
   }
 }
Ejemplo n.º 2
0
 private async Task OnProcess(IDictionary<string, object> owinenv)
 {
   var env = new OWINEnv(owinenv);
   var cancel_token = env.CallCanlelled;
   try {
     if (!HTTPUtils.CheckAuthorization(env.GetAuthorizationToken(), env.AccessControlInfo)) {
       throw new HTTPError(HttpStatusCode.Unauthorized);
     }
     if (env.RequestMethod!="HEAD" && env.RequestMethod!="GET") {
       throw new HTTPError(HttpStatusCode.MethodNotAllowed);
     }
     var query = env.RequestParameters;
     string value;
     if (query.TryGetValue("cmd", out value)) {
       switch (value) {
       case "viewxml": //リレー情報XML出力
         await OnViewXML(env, query, cancel_token).ConfigureAwait(false);
         break;
       case "stop": //チャンネル停止
         await OnStop(env, query, cancel_token).ConfigureAwait(false);
         break;
       case "bump": //チャンネル再接続
         await OnBump(env, query, cancel_token).ConfigureAwait(false);
         break;
       default:
         throw new HTTPError(HttpStatusCode.BadRequest);
       }
     }
     else {
       throw new HTTPError(HttpStatusCode.BadRequest);
     }
   }
   catch (HTTPError err) {
     env.ResponseStatusCode = (int)err.StatusCode;
   }
   catch (UnauthorizedAccessException) {
     env.ResponseStatusCode = (int)HttpStatusCode.Forbidden;
   }
 }
Ejemplo n.º 3
0
        private async Task OnRedirect(IDictionary <string, object> owinenv)
        {
            var env          = new OWINEnv(owinenv);
            var cancel_token = env.CallCanlelled;

            try {
                if (!HTTPUtils.CheckAuthorization(env.GetAuthorizationToken(), env.AccessControlInfo))
                {
                    throw new HTTPError(HttpStatusCode.Unauthorized);
                }
                if (env.RequestMethod != "HEAD" && env.RequestMethod != "GET")
                {
                    throw new HTTPError(HttpStatusCode.MethodNotAllowed);
                }
                await SendResponseMoveToIndex(env, cancel_token).ConfigureAwait(false);
            }
            catch (HTTPError err) {
                env.ResponseStatusCode = (int)err.StatusCode;
            }
            catch (UnauthorizedAccessException) {
                env.ResponseStatusCode = (int)HttpStatusCode.Forbidden;
            }
        }
Ejemplo n.º 4
0
    private async Task OnProcess(IDictionary<string, object> owinenv)
    {
      var env = new OWINEnv(owinenv);
      var cancel_token = env.CallCanlelled;
      try {
        
        if (!HTTPUtils.CheckAuthorization(env.GetAuthorizationToken(), env.AccessControlInfo)) {
          throw new HTTPError(HttpStatusCode.Unauthorized);
        }
        var ctx = new APIContext(this, this.Application.PeerCast, env.AccessControlInfo);
        var rpc_host = new JSONRPCHost(ctx);
        switch (env.RequestMethod) {
        case "HEAD":
        case "GET":
          await SendJson(env, ctx.GetVersionInfo(), env.RequestMethod!="HEAD", cancel_token);
          break;
        case "POST":
          {
            if (!env.RequestHeaders.ContainsKey("X-REQUESTED-WITH")) {
              throw new HTTPError(HttpStatusCode.BadRequest);
            }
            if (!env.RequestHeaders.ContainsKey("CONTENT-LENGTH")) {
              throw new HTTPError(HttpStatusCode.LengthRequired);
            }
            var body = env.RequestBody;
            var len  = body.Length;
            if (len<=0 || RequestLimit<len) {
              throw new HTTPError(HttpStatusCode.BadRequest);
            }

            try {
              var timeout_token = new CancellationTokenSource(TimeoutLimit);
              var buf = await body.ReadBytesAsync((int)len, CancellationTokenSource.CreateLinkedTokenSource(cancel_token, timeout_token.Token).Token);
              var request_str = System.Text.Encoding.UTF8.GetString(buf);
              JToken res = rpc_host.ProcessRequest(request_str);
              if (res!=null) {
                await SendJson(env, res, true, cancel_token);
              }
              else {
                throw new HTTPError(HttpStatusCode.NoContent);
              }
            }
            catch (OperationCanceledException) {
              throw new HTTPError(HttpStatusCode.RequestTimeout);
            }
          }
          break;
        default:
          throw new HTTPError(HttpStatusCode.MethodNotAllowed);
        }
      }
      catch (HTTPError err) {
        env.ResponseStatusCode = (int)err.StatusCode;
      }
      catch (UnauthorizedAccessException) {
        env.ResponseStatusCode = (int)HttpStatusCode.Forbidden;
      }
    }
Ejemplo n.º 5
0
 private async Task OnRedirect(IDictionary<string, object> owinenv)
 {
   var env = new OWINEnv(owinenv);
   var cancel_token = env.CallCanlelled;
   try {
     if (!HTTPUtils.CheckAuthorization(env.GetAuthorizationToken(), env.AccessControlInfo)) {
       throw new HTTPError(HttpStatusCode.Unauthorized);
     }
     if (env.RequestMethod!="HEAD" && env.RequestMethod!="GET") {
       throw new HTTPError(HttpStatusCode.MethodNotAllowed);
     }
     await SendResponseMoveToIndex(env, cancel_token);
   }
   catch (HTTPError err) {
     env.ResponseStatusCode = (int)err.StatusCode;
   }
   catch (UnauthorizedAccessException) {
     env.ResponseStatusCode = (int)HttpStatusCode.Forbidden;
   }
 }