Authorization
TokenSets
are required to access protected resources.
Integration tokens do not expire and therefore dont have a refresh_token
.
However be sure to store the the refresh_token
for person token sets.
You are required to provide both when making requests on behalf of a person.
The SDK provides a TokenSet
type and TokenSetType
enum (seen below) to help you manage your tokens.
export type TokenSet {
access_token: string;
refresh_token?: string;
expires_in?: number;
type: TokenSetType;
}
export enum TokenSetType = {
Integration = 'integration',
Person = 'person'
}
User Authentication
To authenticate a user first build your login url. This url will redirect the user to the Edlink login page.
Login URLs are structured as follows:
https://ed.link/sso/login
?client_id=[...]
&redirect_uri=[...]
&state=[...]
&response_type=code
The SDK provides a utility function that will build the login url for you.
// Optionally you may provide a state parameter for Endlink to
// passback to you upon authentication of the user
edlink.loginUrl({ redirect_uri: 'https://oauthdebugger.com/debug' });
// This URL doesnt change and can be hardcoded if desired
Once the user has logged in they will be redirected back to your application with a code
query parameter.
You can then exchange this code for a token set.
// Provide this code with the matching `redirect_uri` to recieve a token set
// Store this entire object securely
// You will require more than just the `access_token`
const person_token_set = await edlink.auth.grant({
code: '[...]',
redirect_uri: 'https://oauthdebugger.com/debug'
});
// You can now make requests on behalf of this user
const profile = await edlink.use(person_token_set).my.profile();
Integration Authentication
In order to authenticate as an integration you must go to the edlink dashboard and copy the access_token
from the integration overview.
You can then create a TokenSet with this token and use it to make requests on behalf of the integration.
const integration_token_set = {
access_token: '[...]',
type: TokenSetType.Integration
};
const school = await edlink.use(integration_token_set).schools.fetch('3a95a779-0ed1-499b-a352-9ea30d0bd5ea');