Function: ghub--auth

ghub--auth is a byte-compiled function defined in ghub.el.

Signature

(ghub--auth HOST AUTH &optional USERNAME FORGE)

Implementations

(ghub--auth HOST AUTH &optional USERNAME FORGE) in `ghub.el'.

Undocumented

Source Code

;; Defined in ~/.emacs.d/elpa/ghub-20260401.1239/ghub.el
(cl-defgeneric ghub--auth (host auth &optional username forge)
  (unless username
    (setq username (ghub--username host forge)))
  (if (eq auth 'basic)
      (pcase-exhaustive forge
        ((or 'nil 'forgejo 'gitea 'gogs 'bitbucket)
         (cons "Authorization" (ghub--basic-auth host username)))
        ((or 'github 'gitlab)
         (error "%s does not support basic authentication"
                (capitalize (symbol-name forge)))))
    (cons (pcase-exhaustive forge
            ((or 'nil 'forgejo 'github 'gitea 'gogs 'bitbucket) "Authorization")
            ('gitlab "Private-Token"))
          (if (eq forge 'bitbucket)
              ;; For some undocumented reason Bitbucket supports
              ;; values of the form "token <token>" only for GET
              ;; requests.  For PUT requests we have to use basic
              ;; authentication.  Note that the secret is a token
              ;; (aka "app password"), not the actual password.
              ;; The documentation fails to mention this little
              ;; detail.  See #97.
              (concat "Basic "
                      (base64-encode-string
                       (concat username ":"
                               (ghub--token host username auth nil forge))
                       t))
            (concat
             (and (not (eq forge 'gitlab)) "token ")
             (encode-coding-string
              (cl-typecase auth
                (string auth)
                (null   (ghub--token host username 'ghub nil forge))
                (symbol (ghub--token host username auth  nil forge))
                (t (signal 'wrong-type-argument
                           `((or stringp symbolp) ,auth))))
              'utf-8))))))