import { default } from "https://deno.land/x/dashport@v1.2.1/dashports/templateDashport.ts";
Methods
Adds the serializedId obtained in authenticate method to the _dashport object and to the _sId property of this instance of Dashport. This will help with session management.
One parameter will be the object containing the _dashport object
In OAuth, there is a lot of back and forth communication between the client, the app, and the OAuth provider, when a user want to sign in. Tokens are sent back and forth and user data gets sent back at the end. The middleware function that is returned from the 'authenticate' method bundles up this functionality by executing code depending if a user has been authenticated or not. This allows one method to be used for a seamless OAuth process.
Authenticate method takes in a 'strategy', 'serializer', and 'deserializer'.
Strategies are classes that handle the OAuth process for a specific OAuth provider. A 'strategy' will be an instantiation of a new Strategy class such as GoogleStrategy. When strategies are instantiated, options must be passed in such as a client ID, client secret, redirect URI, etc., for the strategy class to use. ALL strategies made for Dashport MUST have a 'router' method that on successful authentication, returns an authData object with a userInfo property in the form of UserProfile.
Serializers are functions that need to have the following functionalities:
- The serializer function needs to take in one argument which will be the user data in the form of an object. This will be in the shape of the UserProfile interface
- The serializer function needs to specify what the developer wants to do with the user data (e.g. store in a database)
- The serializer function should to specify how to create a serialized ID
- The serializer function should return the serialized ID or an error
Deserializers are functions that need to have the following functionalities:
- The deserializer function needs to take in one parameter which will be the serialized ID
- The deserializer function needs to specify what the developer wants to do with the serialized ID to obtain user info (e.g. fetch user's data from a database)
- The deserializer function needs to return the user info or an Error
EXAMPLE: Using dashport.authenticate as a middleware in Oak import * as dpSettings from './dashport.settings.ts';
router.get('/test', dashport.authenticate( dpSettings.googleStrat, dpSettings.serializerA, dpSettings.deserializerA ), (ctx, next) => { ctx.response.body = 'Hello World'; } );
Usually a middleware function.
Creates a _dashport object that will persist across multiple HTTP requests.
Parameters will be specific to the server framework (e.g. Oak will be ctx and next) Output will usually be invocation of a 'next' function
Deletes any session info that exists on the _dashport object. This will cause the user to go through the OAuth process on the next authenticate call.
Parameters will be specific to the server framework (e.g. Oak will be ctx and next)