private void Listen() { while (httpListener.IsListening) { if (!listening) { return; } HttpListenerContext context; try { context = httpListener.GetContext(); } catch (HttpListenerException e) { Console.Error.WriteLine(e.Message); Console.Error.WriteLine(e.StackTrace); continue; } string rawUrl = context.Request.RawUrl; Console.Out.WriteLine("Processing call to {0}", rawUrl); TokenIssueResult result; if (rawUrl == RequestTokenPath) { result = provider.IssueToken(TokenType.Request, context); } else if (rawUrl == AccessTokenPath) { result = provider.IssueToken(TokenType.Access, context); } else if (rawUrl == AuthorizationPath) { Authorize(context); result = new TokenIssueResult(true); } else { continue; } if (result == null || !result.Success) { context.Response.StatusCode = (int)HttpStatusCode.BadRequest; } else { context.Response.StatusCode = (int)HttpStatusCode.OK; } context.Response.Close(); } }
public TokenIssueResult ProcessIssueRequest(IHttpContext context) { OAuthRequestContext authContext = new OAuthRequestContext(); // Check request parameters try { // TODO: Should we ensure the realm parameter, if present, matches the configured realm? ParseParameters(context, authContext); SetSignProvider(authContext); SetConsumer(authContext); SetRequestId(authContext); SetRequestToken(authContext); SetSignature(context, authContext); CheckVerifier(authContext); } catch (OAuthRequestException ex) { authContext.AddError(ex); TokenIssueResult error = new TokenIssueResult(false, ex.Message, ex.Problem); error.Parameters.Add(authContext.ResponseParameters); return(error); } // Allow the application to decide whether to issue the access token bool isRequestAllowed = AllowRequest(context, authContext); if (isRequestAllowed) { // Allow the application to add additional response parameters AddApplicationResponseParameters(authContext, GetAdditionalResponseParameters(context, authContext)); // Issue the token IssueToken(context, authContext); TokenIssueResult result = new TokenIssueResult(true); result.Parameters.Add(authContext.ResponseParameters); return(result); } else { TokenIssueResult error = new TokenIssueResult(false); error.Parameters.Add(authContext.ResponseParameters); return(error); } }
public TokenIssueResult ProcessIssueRequest(IHttpContext context) { OAuthRequestContext authContext = new OAuthRequestContext(); // Check request parameters try { // TODO: Should we ensure the realm parameter, if present, matches the configured realm? ParseParameters(context, authContext); SetSignProvider(authContext); SetConsumer(authContext); SetRequestId(authContext); SetRequestToken(authContext); SetSignature(context, authContext); CheckVerifier(authContext); } catch (OAuthRequestException ex) { authContext.AddError(ex); TokenIssueResult error = new TokenIssueResult(false, ex.Message, ex.Problem); error.Parameters.Add(authContext.ResponseParameters); return error; } // Allow the application to decide whether to issue the access token bool isRequestAllowed = AllowRequest(context, authContext); if (isRequestAllowed) { // Allow the application to add additional response parameters AddApplicationResponseParameters(authContext, GetAdditionalResponseParameters(context, authContext)); // Issue the token IssueToken(context, authContext); TokenIssueResult result = new TokenIssueResult(true); result.Parameters.Add(authContext.ResponseParameters); return result; } else { TokenIssueResult error = new TokenIssueResult(false); error.Parameters.Add(authContext.ResponseParameters); return error; } }
private void Listen() { while (httpListener.IsListening) { if (!listening) return; HttpListenerContext context; try { context = httpListener.GetContext(); } catch (HttpListenerException e) { Console.Error.WriteLine(e.Message); Console.Error.WriteLine(e.StackTrace); continue; } string rawUrl = context.Request.RawUrl; Console.Out.WriteLine("Processing call to {0}", rawUrl); TokenIssueResult result; if (rawUrl == RequestTokenPath) { result = provider.IssueToken(TokenType.Request, context); } else if (rawUrl == AccessTokenPath) { result = provider.IssueToken(TokenType.Access, context); } else if (rawUrl == AuthorizationPath) { Authorize(context); result = new TokenIssueResult(true); } else { continue; } if (result == null || !result.Success) { context.Response.StatusCode = (int) HttpStatusCode.BadRequest; } else { context.Response.StatusCode = (int) HttpStatusCode.OK; } context.Response.Close(); } }