Login
The login endpoint in Edlink is used to redirect users to their Learning Management System (LMS) or Student Information System (SIS) login page and obtain an authorization code. This code is then used to exchange for tokens via the token endpoint. This document provides a detailed guide on how to use the login endpoint to obtain an authorization code.
Overview
The login endpoint is part of the OAuth2 authorization code flow. It is used to initiate the login process and redirect the user to their LMS/SIS for authentication. Once the user successfully logs in, they are redirected back to your application with an authorization code based on the redirect URI provided.
Step-by-Step Guide
This explains the basic steps to use the login endpoint to obtain an authorization code:
1. Create a Login Link
To create a simple link that logs users into their LMS/SIS from your site:
- I. Visit the Application Overview Page: Go to your application's overview page in the Edlink dashboard.
- II. Retrieve Application ID and Redirect URI: Get your application's Application ID and redirect URI.
- III. Construct the Login URL:
const client_id = 'YOUR_APPLICATION_ID'; const redirect_uri = 'YOUR_REDIRECT_URI'; const state = 'RANDOM_STATE'; // A randomly generated state for security const nonce = 'RANDOM_NONCE'; // A randomly generated nonce for security const loginUrl = `https://ed.link/sso/login?client_id=${client_id}&redirect_uri=${encodeURIComponent(redirect_uri)}&response_type=code&state=${state}&nonce=${nonce}`;
Replace YOUR_APPLICATION_ID
, YOUR_REDIRECT_URI
, RANDOM_STATE
, and RANDOM_NONCE
with your actual values.
2. Redirect Users to the Login URL
Redirect the user to the constructed login URL:
window.location.href = loginUrl;
This link will direct the user to the LMS/SIS login page, where they will authenticate.
3. Handling the Redirect
After the user successfully logs in, Edlink will redirect them to the specified redirect_uri
with additional parameters.
Receiving an Authorization Code
When the user is redirected back to your site, the URL will contain the authorization code and state parameters:
https://yoursite.com/?state=RANDOM_STATE&code=AUTHORIZATION_CODE
- state: If you specified a state variable in your login URL, Edlink will pass this back to you. Verify that this variable did not change.
- code: This is the user's authorization code. You will need this code to exchange for tokens.
Example: Full Flow
Here’s a full example of the flow, including constructing the login URL, redirecting the user, and handling the redirect:
Step 1: Create the Login URL
const client_id = 'YOUR_APPLICATION_ID';
const redirect_uri = 'YOUR_REDIRECT_URI';
const state = 'RANDOM_STATE'; // Generate a random state for security
const nonce = 'RANDOM_NONCE'; // Generate a random nonce for security
const loginUrl = `https://ed.link/sso/login?client_id=${client_id}&redirect_uri=${encodeURIComponent(redirect_uri)}&response_type=code&state=${state}&nonce=${nonce}`;
Step 2: Redirect the User
Redirect the user to the login URL:
window.location.href = loginUrl;
Step 3: Handle the Redirect and Retrieve the Authorization Code
In your server-side code, handle the redirect and retrieve the authorization code:
const express = require('express');
const app = express();
app.get('/your-redirect-uri', (req, res) => {
const { code, state } = req.query;
// Verify the state parameter
if (state !== 'RANDOM_STATE') {
return res.status(403).send('State parameter mismatch');
}
// Exchange the authorization code for tokens
// ... (See the guide on using the token endpoint)
res.send(`Authorization code: ${code}`);
});
app.listen(3000, () => {
console.log('Server running on port 3000');
});
Conclusion
The login endpoint in Edlink is used to initiate the OAuth2 authorization code flow, redirecting users to their LMS/SIS for authentication and obtaining an authorization code. By following this guide, you can construct the login URL, redirect users for authentication, and handle the redirect to retrieve the authorization code. For more detailed information, refer to the official Edlink documentation.