Skip to content

Instantly share code, notes, and snippets.

View PascalSenn's full-sized avatar
🌶️

PascalSenn

🌶️
View GitHub Profile
@PascalSenn
PascalSenn / .cs
Created March 12, 2020 20:57
Authentication Provider
services.AddAuthentication(options =>
{
options.DefaultScheme = "YOURSCHEMANAME";
options.DefaultAuthenticateScheme = "YOURSCHEMANAME";
})
.AddJwtBearer("Websockets", ctx => { })
.AddIdentityServerAuthentication("YOURSCHEMANAME", options =>
{
options.ForwardDefaultSelector = context =>
{
@PascalSenn
PascalSenn / .cs
Created March 12, 2020 20:33
HotChocolate SocketInterceptor for Apollo Client Subscriptions
namespace ApolloClient.Examples
{
public class AuthenticationSocketInterceptor : ISocketConnectionInterceptor<HttpContext>
{
// This is the key to the auth token in the HTTP Context
public static readonly string HTTP_CONTEXT_WEBSOCKET_AUTH_KEY = "websocket-auth-token";
// This is the key that apollo uses in the connection init request
public static readonly string WEBOCKET_PAYLOAD_AUTH_KEY = "authToken";
private readonly IAuthenticationSchemeProvider _schemes;
public sealed class UseOffsetPagingAttribute : DescriptorAttribute
{
protected override void TryConfigure(
HotChocolate.Types.Descriptors.IDescriptorContext context,
IDescriptor descriptor,
ICustomAttributeProvider element)
{
if (element is MemberInfo m)
{
docker run --name mongo -p 27017:27017 -d mongo mongod
@PascalSenn
PascalSenn / objectStateHook
Created October 24, 2019 08:34
ObjectStatehook
function useObjectState<T, K extends keyof T>(
key: K,
objState: [T, Dispatch<SetStateAction<T>>]
): [T[K], (val: T[K]) => void] {
const [obj, setObj] = objState;
const setKey = (val: T[K]) => setObj({ ...obj, [key]: val });
return [obj[key], setKey];
}