{"id":13703055,"url":"https://github.com/koesie10/webauthn","last_synced_at":"2025-03-08T15:30:31.112Z","repository":{"id":56187896,"uuid":"149280919","full_name":"koesie10/webauthn","owner":"koesie10","description":"Go package for easy WebAuthn integration","archived":true,"fork":false,"pushed_at":"2020-11-21T19:16:29.000Z","size":76,"stargazers_count":166,"open_issues_count":6,"forks_count":15,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-02-12T10:30:30.037Z","etag":null,"topics":["2fa","2factor","authentication","login","passwordless","webauthn"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/koesie10.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-09-18T11:58:05.000Z","updated_at":"2025-02-06T14:42:23.000Z","dependencies_parsed_at":"2022-08-15T14:20:28.569Z","dependency_job_id":null,"html_url":"https://github.com/koesie10/webauthn","commit_stats":null,"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/koesie10%2Fwebauthn","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/koesie10%2Fwebauthn/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/koesie10%2Fwebauthn/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/koesie10%2Fwebauthn/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/koesie10","download_url":"https://codeload.github.com/koesie10/webauthn/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":242571001,"owners_count":20151403,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["2fa","2factor","authentication","login","passwordless","webauthn"],"created_at":"2024-08-02T21:00:49.675Z","updated_at":"2025-03-08T15:30:30.835Z","avatar_url":"https://github.com/koesie10.png","language":"Go","funding_links":[],"categories":["Server Libraries"],"sub_categories":[],"readme":"# webauthn : Web Authentication API in Go\r\n\r\n## Overview [![GoDoc](https://godoc.org/github.com/koesie10/webauthn?status.svg)](https://godoc.org/github.com/koesie10/webauthn) [![Build Status](https://travis-ci.org/koesie10/webauthn.svg?branch=master)](https://travis-ci.org/koesie10/webauthn)\r\n\r\nThis project provides a low-level and a high-level API to use the [Web Authentication API](https://www.w3.org/TR/webauthn/) (WebAuthn).\r\n\r\n[Demo](https://github.com/koesie10/webauthn-demo)\r\n\r\n## Install\r\n\r\n```\r\ngo get github.com/koesie10/webauthn\r\n```\r\n\r\n## Attestation\r\n\r\nBy default, this library does not support any attestation statement formats. To use the default attestation formats,\r\nyou will need to import `github.com/koesie10/webauthn/attestation` or any of its subpackages if you would just like\r\nto support some attestation statement formats.\r\n\r\nPlease note that the Android SafetyNet attestation statement format depends on\r\n[`gopkg.in/square/go-jose.v2`](https://github.com/square/go-jose), which means that this package will be imported\r\nwhen you import either `github.com/koesie10/webauthn/attestation` or\r\n`github.com/koesie10/webauthn/attestation/androidsafetynet`.\r\n\r\n## High-level API\r\n\r\nThe high-level API can be used with the `net/http` package and simplifies the low-level API. It is located in the `webauthn` subpackage. It is intended\r\nfor use with e.g. `fetch` or `XMLHttpRequest` JavaScript clients.\r\n\r\nFirst, make sure your user entity implements [`User`](https://godoc.org/github.com/koesie10/webauthn/webauthn#User). Then, create a new entity\r\nimplements [`Authenticator`](https://godoc.org/github.com/koesie10/webauthn/webauthn#Authenticator) that stores each authenticator the user\r\nregisters.\r\n\r\nThen, either make your existing repository implement [`AuthenticatorStore`](https://godoc.org/github.com/koesie10/webauthn/webauthn#AuthenticatorStore)\r\nor create a new repository.\r\n\r\nFinally, you can create the main [`WebAuthn`](https://godoc.org/github.com/koesie10/webauthn/webauthn#WebAuthn) struct supplying the\r\n[`Config`](https://godoc.org/github.com/koesie10/webauthn/webauthn#Config) options:\r\n\r\n```golang\r\nw, err := webauthn.New(\u0026webauthn.Config{\r\n    // A human-readable identifier for the relying party (i.e. your app), intended only for display.\r\n    RelyingPartyName:   \"webauthn-demo\",\r\n    // Storage for the authenticator.\r\n    AuthenticatorStore: storage,\r\n})\t\t\r\n```\r\n\r\nThen, you can use the methods defined, such as [`StartRegistration`](https://godoc.org/github.com/koesie10/webauthn/webauthn#WebAuthn.StartRegistration)\r\nto handle registration and login. Every handler requires a [`Session`](https://godoc.org/github.com/koesie10/webauthn/webauthn#Session), which stores\r\nintermediate registration/login data. If you use [`gorilla/sessions`](https://github.com/gorilla/sessions), use\r\n[`webauthn.WrapMap`](https://godoc.org/github.com/koesie10/webauthn/webauthn#WrapMap)`(session.Values)`. Read the documentation for complete information\r\non what parameters need to be passed and what values are returned.\r\n\r\nFor example, a handler for finishing the registration might look like this:\r\n\r\n```golang\r\nfunc (r *http.Request, rw http.ResponseWriter) {\r\n    ctx := r.Context()\r\n\r\n    // Get the user in some way, in this case from the context\r\n    user, ok := UserFromContext(ctx)\r\n    if !ok {\r\n        rw.WriteHeader(http.StatusForbidden)\r\n        return\r\n    }\r\n\r\n    // Get or create a session in some way, in this case from the context\r\n    sess := SessionFromContext(ctx)\r\n\r\n    // Then call FinishRegistration to register the authenticator to the user\r\n    h.webauthn.FinishRegistration(r, rw, user, webauthn.WrapMap(sess))\r\n}\r\n```\r\n\r\nA complete demo application using the high-level API which implements all of these interfaces and stores data in memory is available\r\n[here](https://github.com/koesie10/webauthn-demo).\r\n\r\n## JavaScript examples\r\n\r\n[This class](webauthn.js) is an example that can be used to handle the registration and login phases. It can be used as follows:\r\n\r\n```javascript\r\nconst w = new WebAuthn();\r\n\r\n// Registration\r\nw.register().then(() =\u003e {\r\n    alert('This authenticator has been registered.');\r\n}).catch(err =\u003e {\r\n    console.error(err);\r\n    alert('Failed to register: ' + err);\r\n});\r\n\r\n// Login\r\nw.login().then(() =\u003e {\r\n    alert('You have been logged in.');\r\n}).catch(err =\u003e {\r\n    console.error(err);\r\n    alert('Failed to login: ' + err);\r\n});\r\n```\r\n\r\nOr, with latest `async/await` paradigm:\r\n\r\n```javascript\r\nconst w = new WebAuthn();\r\n\r\n// Registration\r\ntry {\r\n    await w.register();\r\n    alert('This authenticator has been registered.');\r\n} catch (err) {\r\n    console.error(err)\r\n    alert('Failed to register: ' + err);\r\n}\r\n\r\n// Login\r\ntry {\r\n    await w.login();\r\n    alert('You have been logged in.');\r\n} catch(err) {\r\n    console.error(err);\r\n    alert('Failed to login: ' + err);\r\n}\r\n```\r\n\r\n## Low-level API\r\n\r\nThe low-level closely resembles the specification and the high-level API should be preferred. However, if you would like to use the low-level\r\nAPI, the main entry points are:\r\n\r\n* [`ParseAttestationResponse`](https://godoc.org/github.com/koesie10/webauthn/protocol#ParseAttestationResponse)\r\n* [`IsValidAttestation`](https://godoc.org/github.com/koesie10/webauthn/protocol#IsValidAttestation)\r\n* [`ParseAssertionResponse`](https://godoc.org/github.com/koesie10/webauthn/protocol#ParseAssertionResponse)\r\n* [`IsValidAssertion`](https://godoc.org/github.com/koesie10/webauthn/protocol#IsValidAssertion)\r\n\r\n## License\r\n\r\nMIT.\r\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkoesie10%2Fwebauthn","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkoesie10%2Fwebauthn","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkoesie10%2Fwebauthn/lists"}