Code Explainers
Code explainers tagged #authorization
python
import asyncio import json from fastapi import APIRouter, Depends, HTTPException
Streaming export progress with SSE in FastAPI
server-sent-events
async-generators
streaming
Advanced
8 steps
python
from pathlib import Path from django.contrib.auth.decorators import login_required from django.http import FileResponse, Http404, HttpResponseForbidden
Serving files with access checks in Django
authorization
http-caching
file-serving
Intermediate
7 steps
ruby
class TasksController < ApplicationController before_action :set_project def reorder
Bulk task reordering with upsert_all in Rails
bulk-update
upsert
authorization
Intermediate
8 steps
java
@Configuration @EnableWebSecurity public class ResourceServerConfig {
Configuring a JWT resource server in Spring
oauth2
jwt
authorization
Intermediate
8 steps
python
from django.contrib.auth.mixins import LoginRequiredMixin, UserPassesTestMixin from django.shortcuts import get_object_or_404 from django.views.generic import DetailView
Team membership access control in Django
access-control
mixins
class-based-views
Intermediate
7 steps
typescript
import { CanActivate, ExecutionContext, Injectable,
How guards chain auth in NestJS
guards
authentication
authorization
Intermediate
8 steps
python
from fastapi import APIRouter, Depends, HTTPException, status from fastapi.security import OAuth2PasswordBearer from jose import JWTError, jwt from sqlalchemy.orm import Session
Chaining auth dependencies in FastAPI
dependency-injection
jwt-authentication
authorization
Intermediate
8 steps
java
@Configuration @EnableWebSecurity public class OAuth2SecurityConfig {
How OIDC login works in Spring Security
oauth2
openid-connect
authorization
Intermediate
8 steps
typescript
import { Injectable, UnauthorizedException } from '@nestjs/common'; import { PassportStrategy } from '@nestjs/passport'; import { ExtractJwt, Strategy } from 'passport-jwt'; import { ConfigService } from '@nestjs/config';
How a JWT strategy authenticates in NestJS
authentication
jwt
passport
Intermediate
7 steps
typescript
import { CanActivate, ExecutionContext, Injectable, UnauthorizedException } from '@nestjs/common'; import { GqlExecutionContext } from '@nestjs/graphql'; import { Reflector } from '@nestjs/core'; import { JwtService } from '@nestjs/jwt';
How a GraphQL auth guard works in NestJS
authentication
authorization
jwt
Intermediate
7 steps
ruby
class DocumentsController < ApplicationController before_action :authenticate_user! before_action :set_document
Serving secure file downloads in Rails
authorization
signed-urls
active-storage
Intermediate
8 steps
rust
use axum::{ body::Body, extract::MatchedPath, http::{Request, StatusCode},
An admin route guard in Axum middleware
middleware
authorization
request-extensions
Intermediate
7 steps
java
@RestController @RequestMapping("/api/documents") @RequiredArgsConstructor public class DocumentController {
Method-level authorization with @PreAuthorize in Spring
authorization
spel
rest-api
Intermediate
7 steps
php
<?php namespace App\Http\Requests;
How a Laravel FormRequest validates invoices
validation
authorization
form-request
Intermediate
6 steps
php
<?php namespace App\Http\Controllers;
Time-limited signed download links in Laravel
signed urls
authorization
file streaming
Intermediate
6 steps
php
<?php namespace App\Http\Requests;
Normalizing input in a Laravel FormRequest
validation
authorization
input-normalization
Intermediate
6 steps
go
package api func RegisterRoutes(r *gin.Engine, deps *Dependencies) { r.GET("/health", func(c *gin.Context) {
Layering route groups and middleware in Gin
routing
middleware
authentication
Intermediate
8 steps
php
use Illuminate\Support\Facades\Route; use App\Http\Controllers\Admin\DashboardController; use App\Http\Controllers\Admin\UserController; use App\Http\Controllers\Admin\ReportController;
How nested route groups compose in Laravel
routing
middleware
authorization
Intermediate
8 steps