Security News
Input Validation Vulnerabilities Dominate MITRE's 2024 CWE Top 25 List
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
@simpleview/auth-client
Advanced tools
Client for communicating with sv-auth
npm install @simpleview/auth-client
Add the token from the header into your context.
const { getTokenFromHeaders } = require("@simpleview/auth-client");
const server = new ApolloServer({
...
context: ({ req }) => {
return {
...
token : getTokenFromHeaders(req.headers)
};
}
});
In a resolver utilize AuthClient.getUser()
to convert that token into a user. If you look at the sv-auth
project you can see an example of this pattern. In that project TODO ADD URL, admin
requires an acct_id and all child-resolvers will have the user already attached to the context.
AuthClient
is a class for converting a token
and an acct_id
into an auth_user
with permissions.
const { AuthClient } = require("@simpleview/auth-client");
// the GRAPH_URL is the graphQL server that you wish to communicate with. Get the proper URL from the sv-auth repository to align with the appropriate live/dev/staging resource.
const authClient = new AuthClient({ graphUrl : GRAPH_URL });
This method wraps the call to auth.users_current
in a caching layer to ensure that it's optimal performance and is properly updating if a user's permissions have changed.
Generally you will want to make this call very early in your GraphQL stack in order to make the user available on context for all calls to access.
Returns auth_user
.
const user = authClient.getUser({
token,
acct_id : "0"
});
If you are finished with an AuthClient instance, call authClient.close()
in order to shut it down. Generally this is only needed in unit tests, otherwise there is an internal setInterval
which will keep the process open.
Extracts the token from the authorization
header.
const { getTokenFromHeaders } = require("@simpleview/auth-client");
const server = new ApolloServer({
...
context: ({ req }) => {
return {
token : getTokenFromHeaders(req.headers)
};
}
});
GraphServer
is an API interface to communicate with the auth/admin system's graphQL server to make it a little bit easier to call the various methods.
acct_id
is required for any endpoints on admin
.If you need to set the context at run-time, you can manually update the context via setting graphServer.context.acct_id = "x"
. You cannot set the context
key to a new object or it will not function, manually updated or Object.assign
you're changes in.
const { GraphServer } = require("@simpleview/auth-client");
// the GRAPH_URL is the graphQL server that you wish to communicate with. Get the proper URL from the sv-auth repository to align with the appropriate live/dev/staging resource.
const graphServer = new GraphServer({
graphUrl : GRAPH_URL
});
The easiest way to find the endpoints on GraphServer is to either check the src/graphql
or simply new the instance and console log.
Examples
const result = await graphServer.users.login({
email : "x",
password : "y",
fields : "success message"
});
const result = await graphServer.roles.find({
filter : {
acct_id : "0"
},
fields : `
docs {
id
name
...
}
count
`
});
For the available fields on each call you can reference the GraphQL schema via the schema browser.
FAQs
Client for communicating with sv-auth
We found that @simpleview/auth-client demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.
Research
Security News
A threat actor's playbook for exploiting the npm ecosystem was exposed on the dark web, detailing how to build a blockchain-powered botnet.