[{"data":1,"prerenderedAt":1313},["ShallowReactive",2],{"navigation_docs":3,"-backend-development-authentication":377,"-backend-development-authentication-surround":1308},[4,39,114,144,184,244,293,362],{"title":5,"icon":6,"path":7,"stem":8,"children":9,"page":6},"Getting Started",false,"\u002Fgetting-started","1.getting-started",[10,15,20,25,30,35],{"title":11,"path":12,"stem":13,"icon":14},"Learning Path","\u002Fgetting-started\u002Flearning-path","1.getting-started\u002F1.learning-path","i-lucide-map",{"title":16,"path":17,"stem":18,"icon":19},"Introduction","\u002Fgetting-started\u002Fintroduction","1.getting-started\u002F2.introduction","i-lucide-house",{"title":21,"path":22,"stem":23,"icon":24},"Installation","\u002Fgetting-started\u002Finstallation","1.getting-started\u002F3.installation","i-lucide-download",{"title":26,"path":27,"stem":28,"icon":29},"Your First Program","\u002Fgetting-started\u002Ffirst-program","1.getting-started\u002F4.first-program","i-lucide-play",{"title":31,"path":32,"stem":33,"icon":34},"Modules and Dependencies","\u002Fgetting-started\u002Fmodules-and-dependencies","1.getting-started\u002F5.modules-and-dependencies","i-lucide-package-open",{"title":36,"path":37,"stem":38,"icon":34},"Advanced Modules","\u002Fgetting-started\u002Fadvanced-modules","1.getting-started\u002F6.advanced-modules",{"title":40,"path":41,"stem":42,"children":43,"page":6},"Fundamentals","\u002Ffundamentals","2.fundamentals",[44,49,54,59,64,69,74,79,84,89,94,99,104,109],{"title":45,"path":46,"stem":47,"icon":48},"Program Structure","\u002Ffundamentals\u002Fprogram-structure","2.fundamentals\u002F1.program-structure","i-lucide-workflow",{"title":50,"path":51,"stem":52,"icon":53},"Structs and Methods","\u002Ffundamentals\u002Fstructs-and-methods","2.fundamentals\u002F10.structs-and-methods","i-lucide-box",{"title":55,"path":56,"stem":57,"icon":58},"Interfaces","\u002Ffundamentals\u002Finterfaces","2.fundamentals\u002F11.interfaces","i-lucide-plug",{"title":60,"path":61,"stem":62,"icon":63},"Error Handling","\u002Ffundamentals\u002Ferrors","2.fundamentals\u002F12.errors","i-lucide-triangle-alert",{"title":65,"path":66,"stem":67,"icon":68},"Defined Types and Type Aliases","\u002Ffundamentals\u002Fdefined-types","2.fundamentals\u002F13.defined-types","i-lucide-tags",{"title":70,"path":71,"stem":72,"icon":73},"Generics","\u002Ffundamentals\u002Fgenerics","2.fundamentals\u002F14.generics","i-lucide-blocks",{"title":75,"path":76,"stem":77,"icon":78},"Project Structure","\u002Ffundamentals\u002Fproject-structure","2.fundamentals\u002F2.project-structure","i-lucide-folder-tree",{"title":80,"path":81,"stem":82,"icon":83},"Project Layout","\u002Ffundamentals\u002Fproject-layout","2.fundamentals\u002F3.project-layout","i-lucide-layout",{"title":85,"path":86,"stem":87,"icon":88},"Variables and Data Types","\u002Ffundamentals\u002Fvariables-and-types","2.fundamentals\u002F4.variables-and-types","i-lucide-variable",{"title":90,"path":91,"stem":92,"icon":93},"Functions","\u002Ffundamentals\u002Ffunctions","2.fundamentals\u002F5.functions","i-lucide-braces",{"title":95,"path":96,"stem":97,"icon":98},"Control Statements","\u002Ffundamentals\u002Fcontrol-statements","2.fundamentals\u002F6.control-statements","i-lucide-git-branch",{"title":100,"path":101,"stem":102,"icon":103},"Pointers","\u002Ffundamentals\u002Fpointers","2.fundamentals\u002F7.pointers","i-lucide-mouse-pointer-2",{"title":105,"path":106,"stem":107,"icon":108},"Arrays and Slices","\u002Ffundamentals\u002Farrays-and-slices","2.fundamentals\u002F8.arrays-and-slices","i-lucide-list",{"title":110,"path":111,"stem":112,"icon":113},"Maps","\u002Ffundamentals\u002Fmaps","2.fundamentals\u002F9.maps","i-lucide-table-properties",{"title":115,"path":116,"stem":117,"children":118,"page":6},"Concurrency","\u002Fconcurrency","3.concurrency",[119,124,129,134,139],{"title":120,"path":121,"stem":122,"icon":123},"Concurrency Model","\u002Fconcurrency\u002Fconcurrency-model","3.concurrency\u002F1.concurrency-model","i-lucide-network",{"title":125,"path":126,"stem":127,"icon":128},"Goroutines","\u002Fconcurrency\u002Fgoroutines","3.concurrency\u002F2.goroutines","i-lucide-git-fork",{"title":130,"path":131,"stem":132,"icon":133},"Channels","\u002Fconcurrency\u002Fchannels","3.concurrency\u002F3.channels","i-lucide-arrow-left-right",{"title":135,"path":136,"stem":137,"icon":138},"Select and Cancellation","\u002Fconcurrency\u002Fselect-and-cancellation","3.concurrency\u002F4.select-and-cancellation","i-lucide-circle-stop",{"title":140,"path":141,"stem":142,"icon":143},"Synchronization","\u002Fconcurrency\u002Fsynchronization","3.concurrency\u002F5.synchronization","i-lucide-lock-keyhole",{"title":145,"path":146,"stem":147,"children":148,"page":6},"Standard Library","\u002Fstandard-library","4.standard-library",[149,154,159,164,169,174,179],{"title":150,"path":151,"stem":152,"icon":153},"Standard Library Overview","\u002Fstandard-library\u002Foverview","4.standard-library\u002F1.overview","i-lucide-library",{"title":155,"path":156,"stem":157,"icon":158},"Text and Formatting","\u002Fstandard-library\u002Ftext-and-formatting","4.standard-library\u002F2.text-and-formatting","i-lucide-text",{"title":160,"path":161,"stem":162,"icon":163},"Files and JSON","\u002Fstandard-library\u002Ffiles-and-json","4.standard-library\u002F3.files-and-json","i-lucide-file-json",{"title":165,"path":166,"stem":167,"icon":168},"HTTP Clients and Servers","\u002Fstandard-library\u002Fhttp","4.standard-library\u002F4.http","i-lucide-server",{"title":170,"path":171,"stem":172,"icon":173},"Testing","\u002Fstandard-library\u002Ftesting","4.standard-library\u002F5.testing","i-lucide-flask-conical",{"title":175,"path":176,"stem":177,"icon":178},"Command-Line Tools and Configuration","\u002Fstandard-library\u002Fcommand-line-and-configuration","4.standard-library\u002F6.command-line-and-configuration","i-lucide-terminal-square",{"title":180,"path":181,"stem":182,"icon":183},"Structured Logging","\u002Fstandard-library\u002Fstructured-logging","4.standard-library\u002F7.structured-logging","i-lucide-scroll-text",{"title":185,"path":186,"stem":187,"children":188,"page":6},"Backend Development","\u002Fbackend-development","5.backend-development",[189,194,199,204,209,214,219,224,229,234,239],{"title":190,"path":191,"stem":192,"icon":193},"Backend Roadmap","\u002Fbackend-development\u002Fbackend-roadmap","5.backend-development\u002F1.backend-roadmap","i-lucide-route",{"title":195,"path":196,"stem":197,"icon":198},"Graceful Shutdown","\u002Fbackend-development\u002Fgraceful-shutdown","5.backend-development\u002F10.graceful-shutdown","i-lucide-power",{"title":200,"path":201,"stem":202,"icon":203},"Production Checklist","\u002Fbackend-development\u002Fproduction-checklist","5.backend-development\u002F11.production-checklist","i-lucide-clipboard-check",{"title":205,"path":206,"stem":207,"icon":208},"HTTP API Design","\u002Fbackend-development\u002Fhttp-api-design","5.backend-development\u002F2.http-api-design","i-lucide-waypoints",{"title":210,"path":211,"stem":212,"icon":213},"Middleware","\u002Fbackend-development\u002Fmiddleware","5.backend-development\u002F3.middleware","i-lucide-layers-3",{"title":215,"path":216,"stem":217,"icon":218},"Validation","\u002Fbackend-development\u002Fvalidation","5.backend-development\u002F4.validation","i-lucide-list-checks",{"title":220,"path":221,"stem":222,"icon":223},"Application Wiring","\u002Fbackend-development\u002Fapplication-wiring","5.backend-development\u002F5.application-wiring","i-lucide-cable",{"title":225,"path":226,"stem":227,"icon":228},"Observability","\u002Fbackend-development\u002Fobservability","5.backend-development\u002F6.observability","i-lucide-activity",{"title":230,"path":231,"stem":232,"icon":233},"Database SQL","\u002Fbackend-development\u002Fdatabase-sql","5.backend-development\u002F7.database-sql","i-lucide-database",{"title":235,"path":236,"stem":237,"icon":238},"Transactions","\u002Fbackend-development\u002Ftransactions","5.backend-development\u002F8.transactions","i-lucide-repeat-2",{"title":240,"path":241,"stem":242,"icon":243},"Authentication and Authorization","\u002Fbackend-development\u002Fauthentication","5.backend-development\u002F9.authentication","i-lucide-shield-check",{"title":245,"path":246,"stem":247,"children":248,"page":6},"Advanced Go","\u002Fadvanced-go","6.advanced-go",[249,254,259,264,269,274,278,283,288],{"title":250,"path":251,"stem":252,"icon":253},"Advanced Go Roadmap","\u002Fadvanced-go\u002Fadvanced-roadmap","6.advanced-go\u002F1.advanced-roadmap","i-lucide-brain-circuit",{"title":255,"path":256,"stem":257,"icon":258},"Reflection","\u002Fadvanced-go\u002Freflection","6.advanced-go\u002F2.reflection","i-lucide-scan-search",{"title":260,"path":261,"stem":262,"icon":263},"Memory and Garbage Collection","\u002Fadvanced-go\u002Fmemory-and-garbage-collection","6.advanced-go\u002F3.memory-and-garbage-collection","i-lucide-memory-stick",{"title":265,"path":266,"stem":267,"icon":268},"Benchmarking and Profiling","\u002Fadvanced-go\u002Fbenchmarking-and-profiling","6.advanced-go\u002F4.benchmarking-and-profiling","i-lucide-gauge",{"title":270,"path":271,"stem":272,"icon":273},"Advanced Testing and Fuzzing","\u002Fadvanced-go\u002Fadvanced-testing-and-fuzzing","6.advanced-go\u002F5.advanced-testing-and-fuzzing","i-lucide-microscope",{"title":275,"path":276,"stem":277,"icon":48},"Advanced Concurrency","\u002Fadvanced-go\u002Fadvanced-concurrency","6.advanced-go\u002F6.advanced-concurrency",{"title":279,"path":280,"stem":281,"icon":282},"Unsafe and C Boundaries","\u002Fadvanced-go\u002Funsafe-and-cgo","6.advanced-go\u002F7.unsafe-and-cgo","i-lucide-radiation",{"title":284,"path":285,"stem":286,"icon":287},"Package and API Design","\u002Fadvanced-go\u002Fpackage-and-api-design","6.advanced-go\u002F8.package-and-api-design","i-lucide-boxes",{"title":289,"path":290,"stem":291,"icon":292},"Distributed Reliability","\u002Fadvanced-go\u002Fdistributed-reliability","6.advanced-go\u002F9.distributed-reliability","i-lucide-cloud-cog",{"title":294,"path":295,"stem":296,"children":297,"page":6},"Projects","\u002Fprojects","7.projects",[298,316,332,347],{"title":299,"path":300,"stem":301,"children":302,"icon":305},"CLI Task Manager","\u002Fprojects\u002Fcli-task-manager","7.projects\u002F1.cli-task-manager\u002Findex",[303,306,311],{"title":304,"path":300,"stem":301,"icon":305},"Project — CLI Task Manager","i-lucide-list-todo",{"title":307,"path":308,"stem":309,"icon":310},"CLI — Domain and Storage","\u002Fprojects\u002Fcli-task-manager\u002Fdomain-and-storage","7.projects\u002F1.cli-task-manager\u002F1.domain-and-storage","i-lucide-save",{"title":312,"path":313,"stem":314,"icon":315},"CLI — Commands and Tests","\u002Fprojects\u002Fcli-task-manager\u002Fcommands-and-tests","7.projects\u002F1.cli-task-manager\u002F2.commands-and-tests","i-lucide-terminal",{"title":317,"path":318,"stem":319,"children":320,"icon":323},"Concurrent URL Checker","\u002Fprojects\u002Fconcurrent-url-checker","7.projects\u002F2.concurrent-url-checker\u002Findex",[321,324,328],{"title":322,"path":318,"stem":319,"icon":323},"Project — Concurrent URL Checker","i-lucide-radar",{"title":325,"path":326,"stem":327,"icon":128},"URL Checker — Worker Pipeline","\u002Fprojects\u002Fconcurrent-url-checker\u002Fworker-pipeline","7.projects\u002F2.concurrent-url-checker\u002F1.worker-pipeline",{"title":329,"path":330,"stem":331,"icon":173},"URL Checker — Cancellation and Tests","\u002Fprojects\u002Fconcurrent-url-checker\u002Fcancellation-and-tests","7.projects\u002F2.concurrent-url-checker\u002F2.cancellation-and-tests",{"title":333,"path":334,"stem":335,"children":336},"File-backed API","\u002Fprojects\u002Ffile-backed-api","7.projects\u002F3.file-backed-api\u002Findex",[337,339,343],{"title":338,"path":334,"stem":335},"File-backed notes API",{"title":340,"path":341,"stem":342},"File store and concurrency","\u002Fprojects\u002Ffile-backed-api\u002Ffile-store-and-concurrency","7.projects\u002F3.file-backed-api\u002F1.file-store-and-concurrency",{"title":344,"path":345,"stem":346},"HTTP layer and tests","\u002Fprojects\u002Ffile-backed-api\u002Fhttp-and-tests","7.projects\u002F3.file-backed-api\u002F2.http-and-tests",{"title":348,"path":349,"stem":350,"children":351},"Production REST API","\u002Fprojects\u002Fproduction-rest-api","7.projects\u002F4.production-rest-api\u002Findex",[352,354,358],{"title":353,"path":349,"stem":350},"Production REST API capstone",{"title":355,"path":356,"stem":357},"Persistence and authentication","\u002Fprojects\u002Fproduction-rest-api\u002Fpersistence-and-auth","7.projects\u002F4.production-rest-api\u002F1.persistence-and-auth",{"title":359,"path":360,"stem":361},"Operations and release","\u002Fprojects\u002Fproduction-rest-api\u002Foperations-and-release","7.projects\u002F4.production-rest-api\u002F2.operations-and-release",{"title":363,"path":364,"stem":365,"children":366,"page":6},"Meta","\u002Fmeta","99.meta",[367,372],{"title":368,"path":369,"stem":370,"icon":371},"About","\u002Fmeta\u002Fabout","99.meta\u002F1.about","i-lucide-info",{"title":373,"path":374,"stem":375,"icon":376},"Acknowledgements","\u002Fmeta\u002Facknowledgements","99.meta\u002F2.acknowledgements","i-lucide-heart-handshake",{"id":378,"title":240,"body":379,"description":1300,"extension":1301,"links":1302,"meta":1303,"navigation":1304,"path":241,"seo":1305,"stem":242,"__hash__":1307},"docs\u002F5.backend-development\u002F9.authentication.md",{"type":380,"value":381,"toc":1286},"minimark",[382,388,393,397,416,420,427,433,436,440,443,446,541,544,547,551,554,706,732,739,743,746,763,766,769,773,776,911,914,918,1137,1140,1144,1164,1167,1171,1174,1177,1181,1219,1223,1226,1245,1249,1266,1276,1279,1282],[383,384],"learning-lesson-meta",{"level":385,"prerequisites":386,"time":387},"Advanced","HTTP, middleware, validation, databases, and security fundamentals","65–80 minutes",[389,390,392],"h2",{"id":391},"what-you-will-learn","What you will learn",[394,395,396],"p",{},"By the end of this lesson, you will be able to:",[398,399,400,404,407,410,413],"ul",{},[401,402,403],"li",{},"distinguish authentication from authorization;",[401,405,406],{},"design safe password and session boundaries;",[401,408,409],{},"validate tokens by policy rather than merely decoding them;",[401,411,412],{},"apply authorization to the requested resource;",[401,414,415],{},"recognise the roles of TLS, cookies, CSRF protection, and CORS.",[389,417,419],{"id":418},"authentication-and-authorization-are-different","Authentication and authorization are different",[394,421,422,426],{},[423,424,425],"strong",{},"Authentication"," answers: who is making the request?",[394,428,429,432],{},[423,430,431],{},"Authorization"," answers: may that identity perform this action on this resource?",[394,434,435],{},"A valid login does not grant access to every lesson, account, or administrative operation.",[389,437,439],{"id":438},"password-handling","Password handling",[394,441,442],{},"Never store plaintext passwords or reversible encrypted passwords. Use a maintained password-hashing implementation designed for passwords, with parameters selected from current security guidance.",[394,444,445],{},"Keep hashing behind a narrow interface:",[447,448,453],"pre",{"className":449,"code":450,"language":451,"meta":452,"style":452},"language-go shiki shiki-themes solarized-light material-theme one-dark-pro","type PasswordHasher interface {\n    Hash(password string) (string, error)\n    Compare(encodedHash, password string) error\n}\n","go","",[454,455,456,476,512,535],"code",{"__ignoreMap":452},[457,458,461,465,469,472],"span",{"class":459,"line":460},"line",1,[457,462,464],{"class":463},"sEOdo","type",[457,466,468],{"class":467},"snwKR"," PasswordHasher",[457,470,471],{"class":463}," interface",[457,473,475],{"class":474},"shFME"," {\n",[457,477,479,483,486,490,494,497,500,503,506,509],{"class":459,"line":478},2,[457,480,482],{"class":481},"sisdC","    Hash",[457,484,485],{"class":474},"(",[457,487,489],{"class":488},"syre3","password",[457,491,493],{"class":492},"sF6sA"," string",[457,495,496],{"class":474},")",[457,498,499],{"class":474}," (",[457,501,502],{"class":492},"string",[457,504,505],{"class":474},",",[457,507,508],{"class":492}," error",[457,510,511],{"class":474},")\n",[457,513,515,518,520,523,525,528,530,532],{"class":459,"line":514},3,[457,516,517],{"class":481},"    Compare",[457,519,485],{"class":474},[457,521,522],{"class":488},"encodedHash",[457,524,505],{"class":474},[457,526,527],{"class":488}," password",[457,529,493],{"class":492},[457,531,496],{"class":474},[457,533,534],{"class":492}," error\n",[457,536,538],{"class":459,"line":537},4,[457,539,540],{"class":474},"}\n",[394,542,543],{},"This keeps business logic independent of one implementation and permits parameter upgrades. Do not invent a hashing algorithm or use a fast general-purpose hash such as plain SHA-256 for password storage.",[394,545,546],{},"Login errors should not reveal whether an email exists. Apply rate limiting and monitoring at an appropriate boundary, and consider multi-factor authentication for sensitive systems.",[389,548,550],{"id":549},"server-side-sessions","Server-side sessions",[394,552,553],{},"A common browser design stores an opaque random session ID in a cookie and keeps session state on the server.",[447,555,557],{"className":449,"code":556,"language":451,"meta":452,"style":452},"http.SetCookie(w, &http.Cookie{\n    Name:     \"session\",\n    Value:    opaqueSessionID,\n    Path:     \"\u002F\",\n    HttpOnly: true,\n    Secure:   true,\n    SameSite: http.SameSiteLaxMode,\n    MaxAge:   3600,\n})\n",[454,558,559,591,613,625,641,655,668,686,700],{"__ignoreMap":452},[457,560,561,565,568,571,573,576,578,581,583,585,588],{"class":459,"line":460},[457,562,564],{"class":563},"s45-6","http",[457,566,567],{"class":474},".",[457,569,570],{"class":481},"SetCookie",[457,572,485],{"class":474},[457,574,575],{"class":563},"w",[457,577,505],{"class":474},[457,579,580],{"class":463}," &",[457,582,564],{"class":467},[457,584,567],{"class":474},[457,586,587],{"class":467},"Cookie",[457,589,590],{"class":474},"{\n",[457,592,593,596,599,603,607,610],{"class":459,"line":478},[457,594,595],{"class":563},"    Name",[457,597,598],{"class":474},":",[457,600,602],{"class":601},"sED5a","     \"",[457,604,606],{"class":605},"sVazx","session",[457,608,609],{"class":601},"\"",[457,611,612],{"class":474},",\n",[457,614,615,618,620,623],{"class":459,"line":514},[457,616,617],{"class":563},"    Value",[457,619,598],{"class":474},[457,621,622],{"class":563},"    opaqueSessionID",[457,624,612],{"class":474},[457,626,627,630,632,634,637,639],{"class":459,"line":537},[457,628,629],{"class":563},"    Path",[457,631,598],{"class":474},[457,633,602],{"class":601},[457,635,636],{"class":605},"\u002F",[457,638,609],{"class":601},[457,640,612],{"class":474},[457,642,644,647,649,653],{"class":459,"line":643},5,[457,645,646],{"class":563},"    HttpOnly",[457,648,598],{"class":474},[457,650,652],{"class":651},"sqQ1y"," true",[457,654,612],{"class":474},[457,656,658,661,663,666],{"class":459,"line":657},6,[457,659,660],{"class":563},"    Secure",[457,662,598],{"class":474},[457,664,665],{"class":651},"   true",[457,667,612],{"class":474},[457,669,671,674,676,679,681,684],{"class":459,"line":670},7,[457,672,673],{"class":563},"    SameSite",[457,675,598],{"class":474},[457,677,678],{"class":563}," http",[457,680,567],{"class":474},[457,682,683],{"class":563},"SameSiteLaxMode",[457,685,612],{"class":474},[457,687,689,692,694,698],{"class":459,"line":688},8,[457,690,691],{"class":563},"    MaxAge",[457,693,598],{"class":474},[457,695,697],{"class":696},"sAJzr","   3600",[457,699,612],{"class":474},[457,701,703],{"class":459,"line":702},9,[457,704,705],{"class":474},"})\n",[398,707,708,714,720,726,729],{},[401,709,710,713],{},[454,711,712],{},"HttpOnly"," prevents normal JavaScript access but does not remove all cross-site scripting risk.",[401,715,716,719],{},[454,717,718],{},"Secure"," sends the cookie only over HTTPS.",[401,721,722,725],{},[454,723,724],{},"SameSite"," reduces some cross-site request scenarios; choose the mode from the application's actual flows.",[401,727,728],{},"Rotate the session ID after login or privilege changes.",[401,730,731],{},"Expire and revoke sessions server-side when required.",[394,733,734,735,738],{},"Session identifiers require enough cryptographic randomness. Generate them with ",[454,736,737],{},"crypto\u002Frand",", encode them safely, and never include user information or secrets directly in the token.",[389,740,742],{"id":741},"token-authentication","Token authentication",[394,744,745],{},"A signed token is not automatically trustworthy because it can be parsed. Validation must enforce the expected:",[398,747,748,751,754,757,760],{},[401,749,750],{},"signature algorithm and trusted key;",[401,752,753],{},"issuer;",[401,755,756],{},"audience;",[401,758,759],{},"expiration and not-before rules;",[401,761,762],{},"token purpose and required claims.",[394,764,765],{},"Use a maintained library, lock the algorithm and policy in configuration, and test rejection cases. Do not accept an algorithm merely because the token header requests it.",[394,767,768],{},"Short token lifetimes reduce exposure but do not provide instant revocation by themselves. Design rotation and revocation according to the threat model.",[389,770,772],{"id":771},"authentication-middleware","Authentication middleware",[394,774,775],{},"Middleware can verify credentials and put a small identity value into request context:",[447,777,779],{"className":449,"code":778,"language":451,"meta":452,"style":452},"type Identity struct {\n    UserID string\n    Roles  []string\n}\n\nfunc IdentityFromContext(ctx context.Context) (Identity, bool) {\n    identity, ok := ctx.Value(identityKey).(Identity)\n    return identity, ok\n}\n",[454,780,781,793,801,812,816,822,859,893,907],{"__ignoreMap":452},[457,782,783,785,788,791],{"class":459,"line":460},[457,784,464],{"class":463},[457,786,787],{"class":467}," Identity",[457,789,790],{"class":463}," struct",[457,792,475],{"class":474},[457,794,795,798],{"class":459,"line":478},[457,796,797],{"class":563},"    UserID",[457,799,800],{"class":492}," string\n",[457,802,803,806,809],{"class":459,"line":514},[457,804,805],{"class":563},"    Roles",[457,807,808],{"class":474},"  []",[457,810,811],{"class":492},"string\n",[457,813,814],{"class":459,"line":537},[457,815,540],{"class":474},[457,817,818],{"class":459,"line":643},[457,819,821],{"emptyLinePlaceholder":820},true,"\n",[457,823,824,827,830,832,835,838,840,843,845,847,850,852,855,857],{"class":459,"line":657},[457,825,826],{"class":463},"func",[457,828,829],{"class":481}," IdentityFromContext",[457,831,485],{"class":474},[457,833,834],{"class":488},"ctx",[457,836,837],{"class":467}," context",[457,839,567],{"class":474},[457,841,842],{"class":467},"Context",[457,844,496],{"class":474},[457,846,499],{"class":474},[457,848,849],{"class":467},"Identity",[457,851,505],{"class":474},[457,853,854],{"class":492}," bool",[457,856,496],{"class":474},[457,858,475],{"class":474},[457,860,861,864,866,869,873,876,878,881,883,886,889,891],{"class":459,"line":670},[457,862,863],{"class":563},"    identity",[457,865,505],{"class":474},[457,867,868],{"class":563}," ok",[457,870,872],{"class":871},"su2KV"," :=",[457,874,875],{"class":563}," ctx",[457,877,567],{"class":474},[457,879,880],{"class":481},"Value",[457,882,485],{"class":474},[457,884,885],{"class":563},"identityKey",[457,887,888],{"class":474},").(",[457,890,849],{"class":467},[457,892,511],{"class":474},[457,894,895,899,902,904],{"class":459,"line":688},[457,896,898],{"class":897},"s7Bcg","    return",[457,900,901],{"class":563}," identity",[457,903,505],{"class":474},[457,905,906],{"class":563}," ok\n",[457,908,909],{"class":459,"line":702},[457,910,540],{"class":474},[394,912,913],{},"Do not store passwords, raw tokens, or database connections in context.",[389,915,917],{"id":916},"authorize-the-resource","Authorize the resource",[447,919,921],{"className":449,"code":920,"language":451,"meta":452,"style":452},"func (s *Service) UpdateLesson(ctx context.Context, actor UserID, lessonID LessonID, input Update) error {\n    lesson, err := s.repository.Find(ctx, lessonID)\n    if err != nil {\n        return err\n    }\n    if lesson.OwnerID != actor && !s.permissions.IsAdmin(actor) {\n        return ErrForbidden\n    }\n    return s.repository.Update(ctx, lessonID, input)\n}\n",[454,922,923,983,1018,1035,1043,1048,1092,1099,1103,1132],{"__ignoreMap":452},[457,924,925,927,929,932,935,938,940,943,945,947,949,951,953,955,958,961,963,966,969,971,974,977,979,981],{"class":459,"line":460},[457,926,826],{"class":463},[457,928,499],{"class":474},[457,930,931],{"class":488},"s ",[457,933,934],{"class":463},"*",[457,936,937],{"class":467},"Service",[457,939,496],{"class":474},[457,941,942],{"class":481}," UpdateLesson",[457,944,485],{"class":474},[457,946,834],{"class":488},[457,948,837],{"class":467},[457,950,567],{"class":474},[457,952,842],{"class":467},[457,954,505],{"class":474},[457,956,957],{"class":488}," actor",[457,959,960],{"class":467}," UserID",[457,962,505],{"class":474},[457,964,965],{"class":488}," lessonID",[457,967,968],{"class":467}," LessonID",[457,970,505],{"class":474},[457,972,973],{"class":488}," input",[457,975,976],{"class":467}," Update",[457,978,496],{"class":474},[457,980,508],{"class":492},[457,982,475],{"class":474},[457,984,985,988,990,993,995,998,1000,1003,1005,1008,1010,1012,1014,1016],{"class":459,"line":478},[457,986,987],{"class":563},"    lesson",[457,989,505],{"class":474},[457,991,992],{"class":563}," err",[457,994,872],{"class":871},[457,996,997],{"class":563}," s",[457,999,567],{"class":474},[457,1001,1002],{"class":563},"repository",[457,1004,567],{"class":474},[457,1006,1007],{"class":481},"Find",[457,1009,485],{"class":474},[457,1011,834],{"class":563},[457,1013,505],{"class":474},[457,1015,965],{"class":563},[457,1017,511],{"class":474},[457,1019,1020,1023,1025,1029,1033],{"class":459,"line":514},[457,1021,1022],{"class":897},"    if",[457,1024,992],{"class":563},[457,1026,1028],{"class":1027},"sRBoR"," !=",[457,1030,1032],{"class":1031},"sp8Z5"," nil",[457,1034,475],{"class":474},[457,1036,1037,1040],{"class":459,"line":537},[457,1038,1039],{"class":897},"        return",[457,1041,1042],{"class":563}," err\n",[457,1044,1045],{"class":459,"line":643},[457,1046,1047],{"class":474},"    }\n",[457,1049,1050,1052,1055,1057,1060,1062,1064,1067,1070,1073,1075,1078,1080,1083,1085,1088,1090],{"class":459,"line":657},[457,1051,1022],{"class":897},[457,1053,1054],{"class":563}," lesson",[457,1056,567],{"class":474},[457,1058,1059],{"class":563},"OwnerID",[457,1061,1028],{"class":1027},[457,1063,957],{"class":563},[457,1065,1066],{"class":1027}," &&",[457,1068,1069],{"class":1027}," !",[457,1071,1072],{"class":563},"s",[457,1074,567],{"class":474},[457,1076,1077],{"class":563},"permissions",[457,1079,567],{"class":474},[457,1081,1082],{"class":481},"IsAdmin",[457,1084,485],{"class":474},[457,1086,1087],{"class":563},"actor",[457,1089,496],{"class":474},[457,1091,475],{"class":474},[457,1093,1094,1096],{"class":459,"line":670},[457,1095,1039],{"class":897},[457,1097,1098],{"class":563}," ErrForbidden\n",[457,1100,1101],{"class":459,"line":688},[457,1102,1047],{"class":474},[457,1104,1105,1107,1109,1111,1113,1115,1118,1120,1122,1124,1126,1128,1130],{"class":459,"line":702},[457,1106,898],{"class":897},[457,1108,997],{"class":563},[457,1110,567],{"class":474},[457,1112,1002],{"class":563},[457,1114,567],{"class":474},[457,1116,1117],{"class":481},"Update",[457,1119,485],{"class":474},[457,1121,834],{"class":563},[457,1123,505],{"class":474},[457,1125,965],{"class":563},[457,1127,505],{"class":474},[457,1129,973],{"class":563},[457,1131,511],{"class":474},[457,1133,1135],{"class":459,"line":1134},10,[457,1136,540],{"class":474},[394,1138,1139],{},"Checking only “has role editor” may be insufficient when access depends on tenancy, ownership, state, or field. Enforce permissions at the application boundary even if the UI hides unavailable controls.",[389,1141,1143],{"id":1142},"csrf-cors-and-tls","CSRF, CORS, and TLS",[398,1145,1146,1152,1158],{},[401,1147,1148,1151],{},[423,1149,1150],{},"TLS"," protects credentials and traffic in transit. Production authentication must use HTTPS end to end across untrusted networks.",[401,1153,1154,1157],{},[423,1155,1156],{},"CSRF"," matters when browsers automatically attach credentials such as cookies. Use an appropriate CSRF defence in addition to deliberate SameSite settings.",[401,1159,1160,1163],{},[423,1161,1162],{},"CORS"," controls which browser origins may read responses. It is not authentication and does not stop non-browser clients.",[394,1165,1166],{},"Security headers and proxy configuration must match the deployment. Only trust forwarded headers from known proxies.",[389,1168,1170],{"id":1169},"secrets","Secrets",[394,1172,1173],{},"Load signing keys, database credentials, and client secrets from an approved secret-management mechanism. Do not commit them, expose them through diagnostics, include them in URLs, or log them.",[394,1175,1176],{},"Plan rotation before an incident requires it.",[389,1178,1180],{"id":1179},"common-mistakes","Common mistakes",[398,1182,1183,1189,1195,1201,1207,1213],{},[401,1184,1185,1188],{},[423,1186,1187],{},"Decoding a token without validating its policy:"," attacker-controlled claims become trusted identity.",[401,1190,1191,1194],{},[423,1192,1193],{},"Authorizing only by route:"," resource ownership and tenant boundaries are missed.",[401,1196,1197,1200],{},[423,1198,1199],{},"Returning “email not found” during login:"," account enumeration becomes easier.",[401,1202,1203,1206],{},[423,1204,1205],{},"Putting bearer tokens in URLs:"," logs, history, and referrers can retain them.",[401,1208,1209,1212],{},[423,1210,1211],{},"Treating CORS as an access-control system:"," non-browser requests ignore it.",[401,1214,1215,1218],{},[423,1216,1217],{},"Writing custom cryptography:"," subtle design and implementation errors become security vulnerabilities.",[389,1220,1222],{"id":1221},"practice","Practice",[394,1224,1225],{},"Design authentication for a browser-based lesson application. Include login, session creation, authenticated context, owner\u002Fadmin authorization, logout, session expiry, CSRF protection, and safe error responses.",[1227,1228,1229],"accordion",{},[1230,1231,1234,1242],"accordion-item",{"icon":1232,"label":1233},"i-lucide-lightbulb","Show design outline",[447,1235,1240],{"className":1236,"code":1238,"language":1239,"meta":452},[1237],"language-text","POST \u002Fsessions\n  validate bounded input\n  load account by canonical login identifier\n  compare password hash with constant policy\n  return the same public failure for unknown account or wrong password\n  generate opaque random session ID\n  store only a hash of the session ID when threat model requires it\n  set Secure + HttpOnly + deliberate SameSite cookie\n\nAuthenticated middleware\n  read cookie\n  hash\u002Flookup active session\n  check expiry and account state\n  place minimal Identity in request context\n\nApplication service\n  load requested lesson\n  check owner, tenant, and admin rules\n  reject with a stable domain error\n\nPOST \u002Flogout\n  require CSRF protection for cookie-authenticated request\n  revoke server-side session\n  expire cookie\n","text",[454,1241,1238],{"__ignoreMap":452},[394,1243,1244],{},"Use generic public authentication failures while logging a safe internal classification. Rate limiting should consider account, network, and distributed deployment realities without permanently blocking legitimate shared networks.",[389,1246,1248],{"id":1247},"summary","Summary",[398,1250,1251,1254,1257,1260,1263],{},[401,1252,1253],{},"Authentication proves identity; authorization decides access to a concrete action and resource.",[401,1255,1256],{},"Use maintained password-hashing and token libraries with explicit policies.",[401,1258,1259],{},"Protect browser sessions with opaque identifiers and deliberate cookie settings.",[401,1261,1262],{},"Enforce authorization in application logic, not only in the interface or router.",[401,1264,1265],{},"Treat TLS, CSRF, CORS, secret storage, and rotation as separate security concerns.",[394,1267,1268,1269,567],{},"Official reference: ",[1270,1271,1275],"a",{"href":1272,"rel":1273},"https:\u002F\u002Fgo.dev\u002Fdoc\u002Fsecurity\u002Fbest-practices",[1274],"nofollow","Security best practices for Go developers",[1277,1278],"learning-lesson-complete",{},[1280,1281],"learning-lesson-navigation",{"next":196,"next-label":195,"previous":236,"previous-label":235},[1283,1284,1285],"style",{},"html pre.shiki code .sEOdo, html code.shiki .sEOdo{--shiki-light:#859900;--shiki-default:#89DDFF;--shiki-dark:#C678DD}html pre.shiki code .snwKR, html code.shiki .snwKR{--shiki-light:#CB4B16;--shiki-default:#FFCB6B;--shiki-dark:#E5C07B}html pre.shiki code .shFME, html code.shiki .shFME{--shiki-light:#657B83;--shiki-default:#89DDFF;--shiki-dark:#ABB2BF}html pre.shiki code .sisdC, html code.shiki .sisdC{--shiki-light:#268BD2;--shiki-default:#82AAFF;--shiki-dark:#61AFEF}html pre.shiki code .syre3, html code.shiki .syre3{--shiki-light:#657B83;--shiki-light-font-style:inherit;--shiki-default:#EEFFFF;--shiki-default-font-style:italic;--shiki-dark:#E06C75;--shiki-dark-font-style:italic}html pre.shiki code .sF6sA, html code.shiki .sF6sA{--shiki-light:#586E75;--shiki-light-font-weight:bold;--shiki-default:#C792EA;--shiki-default-font-weight:inherit;--shiki-dark:#C678DD;--shiki-dark-font-weight:inherit}html .light .shiki span {color: var(--shiki-light);background: var(--shiki-light-bg);font-style: var(--shiki-light-font-style);font-weight: var(--shiki-light-font-weight);text-decoration: var(--shiki-light-text-decoration);}html.light .shiki span {color: var(--shiki-light);background: var(--shiki-light-bg);font-style: var(--shiki-light-font-style);font-weight: var(--shiki-light-font-weight);text-decoration: var(--shiki-light-text-decoration);}html .default .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}html.dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}html pre.shiki code .s45-6, html code.shiki .s45-6{--shiki-light:#268BD2;--shiki-default:#EEFFFF;--shiki-dark:#E06C75}html pre.shiki code .sED5a, html code.shiki .sED5a{--shiki-light:#2AA198;--shiki-default:#89DDFF;--shiki-dark:#98C379}html pre.shiki code .sVazx, html code.shiki .sVazx{--shiki-light:#2AA198;--shiki-default:#C3E88D;--shiki-dark:#98C379}html pre.shiki code .sqQ1y, html code.shiki .sqQ1y{--shiki-light:#B58900;--shiki-default:#FF9CAC;--shiki-dark:#D19A66}html pre.shiki code .sAJzr, html code.shiki .sAJzr{--shiki-light:#D33682;--shiki-default:#F78C6C;--shiki-dark:#D19A66}html pre.shiki code .su2KV, html code.shiki .su2KV{--shiki-light:#859900;--shiki-default:#89DDFF;--shiki-dark:#E5C07B}html pre.shiki code .s7Bcg, html code.shiki .s7Bcg{--shiki-light:#859900;--shiki-light-font-style:inherit;--shiki-default:#89DDFF;--shiki-default-font-style:italic;--shiki-dark:#C678DD;--shiki-dark-font-style:inherit}html pre.shiki code .sRBoR, html code.shiki .sRBoR{--shiki-light:#859900;--shiki-default:#89DDFF;--shiki-dark:#56B6C2}html pre.shiki code .sp8Z5, html code.shiki .sp8Z5{--shiki-light:#B58900;--shiki-default:#89DDFF;--shiki-dark:#D19A66}",{"title":452,"searchDepth":478,"depth":478,"links":1287},[1288,1289,1290,1291,1292,1293,1294,1295,1296,1297,1298,1299],{"id":391,"depth":478,"text":392},{"id":418,"depth":478,"text":419},{"id":438,"depth":478,"text":439},{"id":549,"depth":478,"text":550},{"id":741,"depth":478,"text":742},{"id":771,"depth":478,"text":772},{"id":916,"depth":478,"text":917},{"id":1142,"depth":478,"text":1143},{"id":1169,"depth":478,"text":1170},{"id":1179,"depth":478,"text":1180},{"id":1221,"depth":478,"text":1222},{"id":1247,"depth":478,"text":1248},"Verify identity, enforce permissions, protect sessions, and avoid common web-security mistakes.","md",null,{},{"icon":243},{"description":1306,"title":240},"Learn secure authentication and authorization boundaries in Go, including passwords, sessions, tokens, cookies, CSRF, and permission checks.","3qOjOCVr3rsUJAwdpBX5ZsUO13Vsrz45k-rGX5Hs6c8",[1309,1311],{"title":235,"path":236,"stem":237,"description":1310,"icon":238,"children":-1},"Keep related database changes atomic and avoid mixing transactional and non-transactional work.",{"title":250,"path":251,"stem":252,"description":1312,"icon":253,"children":-1},"Move from writing correct Go to reasoning about runtime behaviour, performance, APIs, and system boundaries.",1794118102756]