MCPcopy Index your code
hub / github.com/coder/coder / userOAuth2GithubDevice

Method userOAuth2GithubDevice

coderd/userauth.go:836–874  ·  view source on GitHub ↗

@Summary Get Github device auth. @ID get-github-device-auth @Security CoderSessionToken @Produce json @Tags Users @Success 200 {object} codersdk.ExternalAuthDevice @Router /api/v2/users/oauth2/github/device [get]

(rw http.ResponseWriter, r *http.Request)

Source from the content-addressed store, hash-verified

834// @Success 200 {object} codersdk.ExternalAuthDevice
835// @Router /api/v2/users/oauth2/github/device [get]
836func (api *API) userOAuth2GithubDevice(rw http.ResponseWriter, r *http.Request) {
837 var (
838 ctx = r.Context()
839 auditor = api.Auditor.Load()
840 aReq, commitAudit = audit.InitRequest[database.APIKey](rw, &audit.RequestParams{
841 Audit: *auditor,
842 Log: api.Logger,
843 Request: r,
844 Action: database.AuditActionLogin,
845 })
846 )
847 aReq.Old = database.APIKey{}
848 defer commitAudit()
849
850 if api.GithubOAuth2Config == nil {
851 httpapi.Write(ctx, rw, http.StatusBadRequest, codersdk.Response{
852 Message: "Github OAuth2 is not enabled.",
853 })
854 return
855 }
856
857 if !api.GithubOAuth2Config.DeviceFlowEnabled {
858 httpapi.Write(ctx, rw, http.StatusBadRequest, codersdk.Response{
859 Message: "Device flow is not enabled for Github OAuth2.",
860 })
861 return
862 }
863
864 deviceAuth, err := api.GithubOAuth2Config.AuthorizeDevice(ctx)
865 if err != nil {
866 httpapi.Write(ctx, rw, http.StatusInternalServerError, codersdk.Response{
867 Message: "Failed to authorize device.",
868 Detail: err.Error(),
869 })
870 return
871 }
872
873 httpapi.Write(ctx, rw, http.StatusOK, deviceAuth)
874}
875
876// @Summary OAuth 2.0 GitHub Callback
877// @ID oauth-20-github-callback

Callers

nothing calls this directly

Calls 6

InitRequestFunction · 0.92
WriteFunction · 0.92
AuthorizeDeviceMethod · 0.80
ContextMethod · 0.65
LoadMethod · 0.45
ErrorMethod · 0.45

Tested by

no test coverage detected