Product
Introducing SSO
Streamline your login process and enhance security by enabling Single Sign-On (SSO) on the Socket platform, now available for all customers on the Enterprise plan, supporting 20+ identity providers.
@machinat/auth
Advanced tools
Readme
This package is the underlying auth module of webview platform. You might want
to use @machinat/webview
unless you want to serve your own web service.
npm install @machinat/core @machinat/http @machinat/auth
# or with yarn
yarn add @machinat/core @machinat/http @machinat/auth
Check the package reference.
Here is a simple example to protect your API with auth module:
import Machinat, { makeFactoryProvider } from '@machinat/core';
import Http from '@machinat/http';
import Auth from '@machinat/auth';
// add the platforms and the authenticator you need
import { LineServerAuthenticator } from '@machinat/line/auth';
const app = Machinat.createApp({
modules: [
Http.initModule({ /* ... */ }),
Auth.initModule({
apiPath: '/auth',
secret: 'xxx-xxx-xxx-xxx',
}),
],
services: [
// provide authenticators of chat platforms
{ porvide: Auth.AuthenticatorList, withProvider: LineServerAuthenticator },
{ // a simple API route
provide: Http.RequestRouteList,
withProvider: makeFactoryProvider({ deps: [Auth.Controller] })(
authController => ({
path: '/myAPI',
handler: async (req, res) => {
// verify request authorization with AuthController
const verifyResult = await authController.verifyAuth(req);
if (verifyResult.ok) {
res.end(JSON.string({ hello: verifyResult.auth.user.uid }));
} else {
res.writeHead(verifyResult.code);
res.end(JSON.string({ error: verifyResult.reason }));
}
}
})
}),
}
]
});
app.start();
import AuthClient from '@machinat/auth/client';
import LineClientAuthenticator from '@machinat/line/auth/client';
(async function main () {
const authClient = new AuthClient({
platform: 'line',
serverUrl: '/auth',
authenticators: [new LineClientAuthenticator({ /* ... */ })],
});
const { token, context } = await authClient.auth();
// use the bearer token to call your API
const response = await fetch({
url: '/myAPI',
headers: { Authorization: `Bearer ${token}` },
});
// use response...
})();
FAQs
This package is the underlying auth module of webview platform. You might want to use [`@machinat/webview`](https://github.com/machinat/machinat/tree/master/packages/webview) unless you want to serve your own web service.
The npm package @machinat/auth receives a total of 19 weekly downloads. As such, @machinat/auth popularity was classified as not popular.
We found that @machinat/auth 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.
Product
Streamline your login process and enhance security by enabling Single Sign-On (SSO) on the Socket platform, now available for all customers on the Enterprise plan, supporting 20+ identity providers.
Security News
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
Security News
As cyber threats become more autonomous, AI-powered defenses are crucial for businesses to stay ahead of attackers who can exploit software vulnerabilities at scale.