100% Free Forever
AI-Powered Learning
Industry Expert Content
Certificates & Badges
Learn At Your Own Pace
Programming

Your First OAuth Integration

A hands-on walkthrough of building a 'Sign in with GitHub' integration end to end: app registration, the redirect, the callback handler, and using the resulting token safely.

FoundationsIntermediate11 min readJul 10, 2026
Analogies

Your First OAuth Integration

This walkthrough builds a real, minimal 'Sign in with GitHub' feature for a small Node.js/Express backend, using the authorization code flow covered earlier. The goal is to go from zero to a working callback route that logs a user in, so you can see how the abstract roles and terms (client, authorization server, redirect_uri, state, tokens) map onto actual code you'd write and ship, including the parts that are easy to get wrong the first time — like validating state and never leaking the client_secret.

🏏

Cricket analogy: This is like moving from studying the laws of cricket in a textbook to actually walking out to the middle for your first net session — the rules about LBW and no-balls only click once you're facing a real ball.

Step 1: Register Your Application

Every real integration starts on the provider's developer settings page — for GitHub, that's Settings → Developer settings → OAuth Apps → New OAuth App. You'll provide a homepage URL and, critically, an 'Authorization callback URL' that must exactly match the redirect_uri your code sends later (for local development this is typically http://localhost:3000/auth/github/callback). Registering returns a client_id (safe to expose in frontend code or a public repo) and a client_secret (which must go into an environment variable or secrets manager, never into version control).

🏏

Cricket analogy: This is like a team formally registering its squad list and home ground address with the league office before the season starts — you can't just show up and play; the venue and roster have to be filed and approved in advance.

Step 2: Build the Authorization Request and Callback

The login button's link should point to your own /auth/github/login route, not directly at GitHub — this gives your server a chance to generate a fresh, random state value, store it in the user's session, and only then build the full https://github.com/login/oauth/authorize URL with client_id, redirect_uri, scope=read:user, and that state. Building the URL server-side like this (rather than hardcoding it in frontend HTML) keeps the state generation tied to an actual server-side session you can later verify.

🏏

Cricket analogy: This is like a fan not walking directly up to the stadium gate, but first stopping at the club's own ticket office to get a numbered token tied to their registered membership, which is only then presented at the gate.

On the callback route, the very first thing your handler must do is compare the state query parameter against the value stored in the session, rejecting the request outright if they don't match. Only after that check passes should you take the code and make the server-to-server POST to https://github.com/login/oauth/access_token, parse the resulting access token from the response, and use it to call https://api.github.com/user to fetch the user's profile before creating your own application session (a cookie, JWT, or similar) — the GitHub access token itself should typically not be handed to the frontend.

🏏

Cricket analogy: This is like the gate steward checking the numbered stub against the office's own log before letting anyone in, and only then radioing the ticket office to confirm the seat — skipping the stub check first would let anyone with a lookalike stub walk straight through.

javascript
// server.js (Express)
const express = require('express');
const crypto = require('crypto');
const app = express();

app.get('/auth/github/login', (req, res) => {
  const state = crypto.randomBytes(16).toString('hex');
  req.session.oauthState = state;

  const params = new URLSearchParams({
    client_id: process.env.GITHUB_CLIENT_ID,
    redirect_uri: 'http://localhost:3000/auth/github/callback',
    scope: 'read:user',
    state,
  });
  res.redirect(`https://github.com/login/oauth/authorize?${params}`);
});

app.get('/auth/github/callback', async (req, res) => {
  const { code, state } = req.query;

  if (!state || state !== req.session.oauthState) {
    return res.status(400).send('Invalid state parameter');
  }
  delete req.session.oauthState;

  const tokenRes = await fetch('https://github.com/login/oauth/access_token', {
    method: 'POST',
    headers: { 'Accept': 'application/json', 'Content-Type': 'application/json' },
    body: JSON.stringify({
      client_id: process.env.GITHUB_CLIENT_ID,
      client_secret: process.env.GITHUB_CLIENT_SECRET,
      code,
      redirect_uri: 'http://localhost:3000/auth/github/callback',
    }),
  });
  const { access_token, error } = await tokenRes.json();
  if (error || !access_token) {
    return res.status(401).send('OAuth token exchange failed');
  }

  const userRes = await fetch('https://api.github.com/user', {
    headers: { Authorization: `Bearer ${access_token}` },
  });
  const githubUser = await userRes.json();

  req.session.userId = githubUser.id;
  req.session.username = githubUser.login;
  res.redirect('/dashboard');
});

Step 3: Use the Token and Handle Errors

Once you have an access token, every subsequent API call should send it in the Authorization: Bearer header and be wrapped in explicit error handling for the two failure modes you'll hit constantly in production: a 401 response meaning the token expired or was revoked (requiring a refresh-token exchange, or if there's no refresh token, a fresh login), and a 403 response meaning the token is valid but lacks the scope needed for that specific call. Treating these as the same generic 'API error' makes debugging integrations painful, so most production code branches on the status code explicitly.

🏏

Cricket analogy: This is like a scorer distinguishing between 'the umpire's radio has lost signal entirely' (401 — needs reconnecting) versus 'the radio works fine but this channel isn't licensed for boundary review footage' (403 — right connection, wrong permission) — treating both the same wastes the whole review.

Store OAuth tokens the way you'd store any other secret: encrypted at rest if persisted server-side, never in localStorage if you can avoid it (localStorage is readable by any JavaScript on the page, including injected via XSS), and prefer an HttpOnly, Secure session cookie for your own app's session once the OAuth handshake is done.

Never commit a client_secret to a git repository, even a private one — it will end up in history forever and in CI logs. Load it from an environment variable or a secrets manager, and add a git-ignored .env file for local development, exactly as this walkthrough's server.js does with process.env.GITHUB_CLIENT_SECRET.

  • Registering an OAuth app requires declaring an exact redirect URI in advance and yields a client_id and client_secret.
  • The login route should be built server-side so a fresh, session-bound state value is generated per request.
  • The callback handler must verify state before doing anything else, rejecting mismatches outright.
  • The code-for-token exchange happens server-to-server, keeping the client_secret out of the browser.
  • The provider's raw access token should generally stay server-side; issue your own app session instead.
  • Distinguish 401 (expired/invalid token) from 403 (valid token, insufficient scope) in error handling.
  • Never commit client_secret to version control; load it from environment variables or a secrets manager.

Practice what you learned

Was this page helpful?

Topics covered

#Programming#OAuth20StudyNotes#YourFirstOAuthIntegration#OAuth#Integration#Step#Register#StudyNotes#SkillVeris#ExamPrep

Frequently Asked Questions

21 categories · pick one to explore

Where can I get free study notes for programming and tech subjects?
SkillVeris offers completely free study notes covering programming and tech subjects, with no signup fees or paywalls. The notes are structured by course and topic, written for quick understanding, and enriched with the Learn Through Hobbies analogy method, so you can revise concepts through cricket, music, gaming, cooking and more.
Are SkillVeris study notes good for exam revision?
Yes, the study notes are designed for efficient revision: each topic answers its heading immediately, keeps explanations concise, and links to related glossary terms and cheat sheets. Students preparing for university exams or certification tests use them as quick revision notes because they distil concepts without the padding of full textbooks.
What subjects do the free study notes cover?
The study notes span the platform's main domains, including AI and machine learning, Python and programming, web development, DevOps, cloud, security and databases. Coverage mirrors the 37 live courses, so notes exist for the topics you are actually studying, and new note sets are added as courses launch.
How are SkillVeris study notes different from regular textbooks?
The notes are answer-first, concise and free, whereas textbooks are long and often expensive. Each section explains one concept directly, then reinforces it through selectable hobby analogies like cricket or cooking. Notes also cross-link to the glossary, blog and cheat sheets, letting you jump to related material instantly instead of flipping pages.
Can I use the developer study material without creating an account?
The study notes are free to access, and SkillVeris does not charge anything for its developer study material at any point. Browsing notes is straightforward from the Study Notes section, and if you want progress tracking, certificates and AI Mentor conversations tied to your learning, a free account unlocks those extras.
Do the study notes explain concepts with analogies?
Yes, this is a signature SkillVeris feature. Study notes use the Learn Through Hobbies method, explaining technical concepts through analogies from twelve domains including cricket, music, gaming, photography, travel, movies, fitness, chess, cooking, finance, business and sports. You can switch the analogy domain instantly to whichever hobby makes the concept click.
Are the revision notes suitable for last-minute exam preparation?
Yes, revision notes on SkillVeris work well for last-minute preparation because every section states the answer in its first sentences, so skimming is genuinely effective. Pair them with the relevant cheat sheet for formulas and syntax, and use the glossary for any unfamiliar term you meet while cramming.
Is there free study material for AI and machine learning?
Yes, SkillVeris provides free study notes across its AI and ML catalogue, covering Python for AI, deep learning frameworks like PyTorch and TensorFlow, Hugging Face Transformers, Large Language Models, RAG, AI agents and MLOps. All of it is free, making it a strong resource for Indian students and global learners alike.
Can beginners understand the study notes, or are they for experts?
Beginners can absolutely use them. The notes are written in plain language, define terms as they appear, and lean on hobby analogies to make abstract ideas concrete. Difficulty scales with the underlying course level, so beginner-course notes stay gentle while advanced-course notes go deeper, and the glossary supports you throughout.
How do study notes connect with SkillVeris courses?
Study notes are organised by course and topic, so they map directly to the structured courses and their 24–40-lesson curriculum. Many learners study a lesson first, then use the matching notes for revision before module assessments and the final exam, where 80 percent is required to pass and earn the certificate.
Are there study notes for Python specifically?
Yes, Python is well covered through notes tied to the Python-focused courses, including Python for AI and ML. Topics span fundamentals through applied machine learning usage. You can reinforce the notes with Python practice in Code Lab, which runs code in your browser with no installation required.
Do the study notes include code examples?
Yes, study notes include code examples wherever a concept is best shown in code, alongside explanations, key points and analogies. Reading a snippet in the notes and then reproducing it yourself in Code Lab is an effective loop, since Code Lab lets you run code in the browser across six languages.
How often is new study material added to SkillVeris?
Study material grows alongside the course catalogue. Whenever new courses join the platform's 37 live courses, matching study notes, glossary entries and cheat sheets are added so the resources stay in sync. Existing notes are also refined over time, so it is worth revisiting topics you studied earlier.
Can I use SkillVeris notes to prepare for technical interviews?
Yes, the notes make excellent interview revision because they compress each concept into direct, answer-first explanations, which mirrors how you should answer interview questions. Combine them with the SkillVeris interview questions feature, which includes readiness scoring, to test whether your revision has actually made you interview-ready.
Are the study notes mobile-friendly for studying on the go?
Yes, the study notes are built to load fast and read comfortably on mobile devices, so you can revise during a commute or between classes. Sections are short and answer-first, which suits small screens, and analogy switching works on mobile too, letting you study anywhere without carrying books.
What is the difference between study notes and cheat sheets?
Study notes explain concepts in depth with context, examples and analogies, making them ideal for learning and revision. Cheat sheets are compact quick-reference summaries of syntax, commands and key facts, ideal once you already understand a topic. Most learners study the notes first, then keep the cheat sheet handy while coding.
Do study notes help if I am stuck on a course lesson?
Yes, reading the matching study notes often clarifies a lesson because the same concept is explained from a different angle, frequently with a different analogy. If you are still stuck, ask the AI Mentor, which answers 24/7 at Quick, Detailed or Deep-dive depth until the idea genuinely makes sense.
Is there free study material for DevOps and cloud topics?
Yes, SkillVeris carries free study notes for DevOps and cloud topics as part of its coverage across 37 live courses. The material suits learners following the DevOps Engineer or Cloud Engineer paths, and it links to related glossary terms and cheat sheets so you can revise the whole toolchain in one place.
Can school or college students in India use these notes for projects?
Yes, students across India and worldwide use SkillVeris notes for coursework, projects and exam preparation, and everything is free, which matters for student budgets. The notes explain concepts clearly enough to cite in project reports, and Code Lab lets you prototype the project code directly in your browser.
How should I combine study notes with other SkillVeris resources?
A proven loop: learn from a course lesson, revise with the matching study notes, look up unfamiliar terms in the glossary, keep the cheat sheet open while practising in Code Lab, and quiz yourself with interview questions. The AI Mentor fills any remaining gaps 24/7, at whatever depth you need.

What Learners Say

Real journeys from the SkillVeris community — swipe for more.

SkillVeris taught me Python through Cricket. Now I’m building real projects and feeling confident!
Arjun S. · B.Tech Student
The best platform for hobby-based learning. Concepts finally stick.
Priya R. · Data Analyst
I went from zero coding to a portfolio of projects — all by learning through my love for gaming. Landed my first internship!
Kabir M. · CS Undergraduate
Trending Topics50 popular tags — tap to explore
Trending CoursesAll 37 free courses — tap to browse