public EmbedIOAuthServer(Uri baseUri, int port, Assembly resourceAssembly, string resourcePath) { Ensure.ArgumentNotNull(baseUri, nameof(baseUri)); BaseUri = baseUri; Port = port; _webServer = new WebServer(port) .WithModule(new ActionModule("/", HttpVerbs.Post, (ctx) => { var query = ctx.Request.QueryString; var error = query["error"]; if (error != null) { throw new AuthException(error, query["state"]); } var requestType = query.Get("request_type"); if (requestType == "token") { ImplictGrantReceived?.Invoke(this, new ImplictGrantResponse( query["access_token"] !, query["token_type"] !, int.Parse(query["expires_in"] !) ) { State = query["state"] });
public EmbedIOAuthServer(Uri baseUri, int port, Assembly resourceAssembly, string resourcePath) { Ensure.ArgumentNotNull(baseUri, nameof(baseUri)); BaseUri = baseUri; Port = port; _webServer = new WebServer(port) .WithModule(new ActionModule("/", HttpVerbs.Post, (ctx) => { var query = ctx.Request.QueryString; if (query["error"] != null) { throw new AuthException(query["error"], query["state"]); } var requestType = query.Get("request_type"); if (requestType == "token") { ImplictGrantReceived?.Invoke(this, new ImplictGrantResponse( query["access_token"], query["token_type"], int.Parse(query["expires_in"]) ) { State = query["state"] }); } if (requestType == "code") { AuthorizationCodeReceived?.Invoke(this, new AuthorizationCodeResponse(query["code"]) { State = query["state"] }); } return(ctx.SendStringAsync("OK", "text/plain", Encoding.UTF8)); })) .WithEmbeddedResources("/auth_assets", Assembly.GetExecutingAssembly(), AssetsResourcePath) .WithEmbeddedResources(baseUri.AbsolutePath, resourceAssembly, resourcePath); }