Skip to content

Instantly share code, notes, and snippets.

@bjoerntx
Created May 27, 2020 14:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bjoerntx/da2340f1523c7d5817d0248555e6dcac to your computer and use it in GitHub Desktop.
Save bjoerntx/da2340f1523c7d5817d0248555e6dcac to your computer and use it in GitHub Desktop.
public class WebSocketAuth : ActionFilterAttribute
{
// stored access token usually retrieved from any storage
// implemented thought OAuth or any other identity protocol
private const string access_token = "821e2f35-86e3-4917-a963-b0c4228d1315";
public override void OnActionExecuting(HttpActionContext actionContext)
{
// retrieve access token from query string
var sAccess_token = HttpUtility.ParseQueryString(
actionContext.Request.RequestUri.Query)["access_token"];
// show case only: easy comparison of tokens
if (sAccess_token != access_token)
throw new UnauthorizedAccessException();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment