feat: OAuth Device Authorization Grant #4830

Open
opened 2024-08-05 21:41:53 +02:00 by abueide · 10 comments

Needs and benefits

Would love to be able to use git-credential-oauth on my headless devices via the device authorization grant flow.

Opening this issue to get the conversation, would love to get started on implementing this myself as my first contribution to forgejo. If anyone has any tips/pointers or considerations before I start it is very appreciated!

Feature Description

Implement https://www.rfc-editor.org/rfc/rfc8628

Screenshots

No response

### Needs and benefits Would love to be able to use [git-credential-oauth](https://github.com/hickford/git-credential-oauth) on my headless devices via the device authorization grant flow. Opening this issue to get the conversation, would love to get started on implementing this myself as my first contribution to forgejo. If anyone has any tips/pointers or considerations before I start it is very appreciated! ### Feature Description Implement https://www.rfc-editor.org/rfc/rfc8628 ### Screenshots _No response_
Owner

Did you try to use this? This should work out of the box since 63ab92d797 and there's documentation for this https://forgejo.org/docs/latest/user/oauth2-provider/#git-authentication

Did you try to use this? This should work out of the box since 63ab92d7971e4931e98f014f2c5385d2242fa780 and there's documentation for this https://forgejo.org/docs/latest/user/oauth2-provider/#git-authentication
Author

Did you try to use this? This should work out of the box since 63ab92d797 and there's documentation for this https://forgejo.org/docs/latest/user/oauth2-provider/#git-authentication

forgive me if I'm wrong, but are you sure that device authorization is supported? I don't see anything mentioned in the docs that says that I can ssh into a headless machine, initiate an oauth flow, copy the link onto another device and be able to authorize the original headless ssh session. The callback url goes to localhost on the device with the browser, i'm unsure how the token is supposed to get back to the headless ssh session.

> Did you try to use this? This should work out of the box since 63ab92d7971e4931e98f014f2c5385d2242fa780 and there's documentation for this https://forgejo.org/docs/latest/user/oauth2-provider/#git-authentication > forgive me if I'm wrong, but are you sure that device authorization is supported? I don't see anything mentioned in the docs that says that I can ssh into a headless machine, initiate an oauth flow, copy the link onto another device and be able to authorize the original headless ssh session. The callback url goes to localhost on the device with the browser, i'm unsure how the token is supposed to get back to the headless ssh session.
Owner

Ah sorry, I think I misread your post. Yeah that's indeed not yet supported.

Ah sorry, I think I misread your post. Yeah that's indeed not yet supported.
Author

I also would like to implement printing out a QR code in the terminal that links to the oauth url like tailscale does with its --qr parameter. Then you can just snap a pic with the phone and authorize in a mobile browser. Will start poking around and trying to learn more about the forgejo oauth code.

I also would like to implement printing out a QR code in the terminal that links to the oauth url like tailscale does with its --qr parameter. Then you can just snap a pic with the phone and authorize in a mobile browser. Will start poking around and trying to learn more about the forgejo oauth code.
Owner

Will start poking around and trying to learn more about the forgejo oauth code.

Feel free to join the development room in Matrix if you have any questions.

> Will start poking around and trying to learn more about the forgejo oauth code. Feel free to join the [development room in Matrix](https://matrix.to/#/#forgejo-development:matrix.org) if you have any questions.
Contributor

@abueide Hey! I would love to have this feature for oauth authentication on our HPC systems, where outgoing ssh connections are blocked and manually handling API tokens is a bit annoying (and less secure than git-credential-oauth). Are you still planning to work on this at some point? Otherwise I might take a stab at it myself, whenever I'd get around to it.

@abueide Hey! I would love to have this feature for oauth authentication on our HPC systems, where outgoing ssh connections are blocked and manually handling API tokens is a bit annoying (and less secure than git-credential-oauth). Are you still planning to work on this at some point? Otherwise I might take a stab at it myself, whenever I'd get around to it.
Owner

I think you're free to go ahead and implement this.

I think you're free to go ahead and implement this.

I gave this a go; you can find a WIP PR here: #10373.

I tested the functionality manually, and it works. You can find setup instructions in the PR description.

Unit/integration test coverage is only marginal, and I could use some help with the UI, since I'm not much of a web person. The UI also looks a bit broken because I haven't figured out how translations work yet.

Feedback would be much appreciated!

I gave this a go; you can find a WIP PR here: https://codeberg.org/forgejo/forgejo/pulls/10373. I tested the functionality manually, and it works. You can find setup instructions in the PR description. Unit/integration test coverage is only marginal, and I could use some help with the UI, since I'm not much of a web person. The UI also looks a bit broken because I haven't figured out how translations work yet. Feedback would be much appreciated!

I just noticed there's a similar PR for gitea here: https://github.com/go-gitea/gitea/pull/35379. Since gitea is MIT licensed, we could also adopt that. Some differences from my approach:

  • it keeps device grants separate from OAuth grants
  • device grant support is configurable per-application
  • doesn't support verification_uri_complete (i.e. to allow clients to use QR-codes / NFC)
I just noticed there's a similar PR for gitea here: https://github.com/go-gitea/gitea/pull/35379. Since gitea is MIT licensed, we could also adopt that. Some differences from my approach: * it keeps device grants separate from OAuth grants * device grant support is configurable per-application * doesn't support verification_uri_complete (i.e. to allow clients to use QR-codes / NFC)
Contributor

@ccmtaylor wrote in #4830 (comment):

I just noticed there's a similar PR for gitea here: https://github.com/go-gitea/gitea/pull/35379. Since gitea is MIT licensed, we could also adopt that. Some differences from my approach:

  • it keeps device grants separate from OAuth grants
  • device grant support is configurable per-application
  • doesn't support verification_uri_complete (i.e. to allow clients to use QR-codes / NFC)

I'm not very familiar with the related RFCs so take this with a grain of salt, but my intuition says:

  1. The device authorization flow is merely an alternative way to authorize a client application. When the authorization is finished there is no difference between the permissions granted to a client application that used the device flow and those granted to one that used the regular flow. So I don't see a point in keeping two separate tables.
  2. Along the same lines, I don't see a point in restricting the allowed authorization flow on a per-application basis. As long as there are no known weaknesses in the spec or implementation the user should be free to use what makes sense given their use-case. In case there is a weakness discovered in the device flow it might make sense to have a configuration option to disable it entirely.

Regarding verification_uri_complete, it would be very useful for my specific use-case: I am using git-credential-oauth on HPC systems via ssh. If Forgejo provides verification_uri_complete and if git-credential-oauth were to just print this full link, then I would just have to click the link to open it in my local browser. This would be almost as convenient as the regular oauth flow, which opens the link automatically.

All that to say: your approach seems preferable to me.

@ccmtaylor wrote in https://codeberg.org/forgejo/forgejo/issues/4830#issuecomment-8849853: > I just noticed there's a similar PR for gitea here: https://github.com/go-gitea/gitea/pull/35379. Since gitea is MIT licensed, we could also adopt that. Some differences from my approach: > > * it keeps device grants separate from OAuth grants > * device grant support is configurable per-application > * doesn't support verification_uri_complete (i.e. to allow clients to use QR-codes / NFC) I'm not very familiar with the related RFCs so take this with a grain of salt, but my intuition says: 1. The device authorization flow is merely an alternative way to authorize a client application. When the authorization is finished there is no difference between the permissions granted to a client application that used the device flow and those granted to one that used the regular flow. So I don't see a point in keeping two separate tables. 2. Along the same lines, I don't see a point in restricting the allowed authorization flow on a per-application basis. As long as there are no known weaknesses in the spec or implementation the user should be free to use what makes sense given their use-case. In case there is a weakness discovered in the device flow it might make sense to have a configuration option to disable it entirely. Regarding verification_uri_complete, it would be very useful for my specific use-case: I am using git-credential-oauth on HPC systems via ssh. If Forgejo provides verification_uri_complete and if git-credential-oauth were to just print this full link, then I would just have to click the link to open it in my local browser. This would be almost as convenient as the regular oauth flow, which opens the link automatically. All that to say: your approach seems preferable to me.
Sign in to join this conversation.
No labels
arch
riscv64
backport/v1.19
backport/v1.20
backport/v1.21/forgejo
backport/v10.0/forgejo
backport/v11.0/forgejo
backport/v12.0/forgejo
backport/v13.0/forgejo
backport/v14.0/forgejo
backport/v15.0/forgejo
backport/v7.0/forgejo
backport/v8.0/forgejo
backport/v9.0/forgejo
breaking
bug
bug
confirmed
bug
duplicate
bug
needs-more-info
bug
new-report
bug
reported-upstream
code/actions
code/api
code/auth
code/auth/faidp
code/auth/farp
code/email
code/federation
code/git
code/migrations
code/packages
code/wiki
database
MySQL
database
PostgreSQL
database
SQLite
dependency-upgrade
dependency
certmagic
dependency
chart.js
dependency
Chi
dependency
Chroma
dependency
citation.js
dependency
codespell
dependency
css-loader
dependency
devcontainers
dependency
dropzone
dependency
editorconfig-checker
dependency
elasticsearch
dependency
enmime
dependency
F3
dependency
ForgeFed
dependency
garage
dependency
Git
dependency
git-backporting
dependency
Gitea
dependency
gitignore
dependency
go-ap
dependency
go-enry
dependency
go-gitlab
dependency
Go-org
dependency
go-rpmutils
dependency
go-sql-driver mysql
dependency
go-swagger
dependency
go-version
dependency
go-webauthn
dependency
gocron
dependency
Golang
dependency
goldmark
dependency
goquery
dependency
Goth
dependency
grpc-go
dependency
happy-dom
dependency
Helm
dependency
image-spec
dependency
jsonschema
dependency
KaTeX
dependency
lint
dependency
MariaDB
dependency
Mermaid
dependency
minio-go
dependency
misspell
dependency
Monaco
dependency
PDFobject
dependency
playwright
dependency
postcss
dependency
postcss-plugins
dependency
pprof
dependency
prometheus client_golang
dependency
protobuf
dependency
relative-time-element
dependency
renovate
dependency
reply
dependency
ssh
dependency
swagger-ui
dependency
tailwind
dependency
temporal-polyfill
dependency
terminal-to-html
dependency
tests-only
dependency
text-expander-element
dependency
urfave
dependency
vfsgen
dependency
vite
dependency
Woodpecker CI
dependency
x tools
dependency
XORM
Discussion
duplicate
enhancement/feature
forgejo/accessibility
forgejo/branding
forgejo/ci
forgejo/commit-graph
forgejo/documentation
forgejo/furnace cleanup
forgejo/i18n
forgejo/interop
forgejo/moderation
forgejo/privacy
forgejo/release
forgejo/scaling
forgejo/security
forgejo/ui
Gain
High
Gain
Nice to have
Gain
Undefined
Gain
Very High
good first issue
i18n/backport-stable
impact
large
impact
medium
impact
small
impact
unknown
Incompatible license
issue
closed
issue
do-not-exist-yet
issue
open
manual test
Manually tested during feature freeze
OS
FreeBSD
OS
Linux
OS
macOS
OS
Windows
problem
QA
regression
release blocker
Release Cycle
Feature Freeze
release-blocker
v7.0
release-blocker
v7.0.1
release-blocker
v7.0.2
release-blocker
v7.0.3
release-blocker
v7.0.4
release-blocker
v8.0.0
release-blocker/v9.0.0
run-all-playwright-tests
run-end-to-end-tests
test
manual
test
needed
test
needs-help
test
not-needed
test
present
untested
User research - time-tracker
valuable code
worth a release-note
User research - Accessibility
User research - Blocked
User research - Community
User research - Config (instance)
User research - Errors
User research - Filters
User research - Future backlog
User research - Git workflow
User research - Labels
User research - Moderation
User research - Needs input
User research - Notifications/Dashboard
User research - Rendering
User research - Repo creation
User research - Repo units
User research - Security
User research - Settings (in-app)
No milestone
No project
No assignees
4 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
forgejo/forgejo#4830
No description provided.