Compare commits
3 Commits
v0.1.3
..
b5ef107f9c
| Author | SHA1 | Date | |
|---|---|---|---|
| b5ef107f9c | |||
| 21a01e9412 | |||
| 77e2610fe8 |
@@ -1,68 +0,0 @@
|
|||||||
name: Build and Publish APK Package
|
|
||||||
on:
|
|
||||||
push:
|
|
||||||
tags:
|
|
||||||
- 'v*'
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
build-apk:
|
|
||||||
runs-on:
|
|
||||||
- ubuntu-24.04
|
|
||||||
container:
|
|
||||||
image: alpine:latest
|
|
||||||
strategy:
|
|
||||||
matrix:
|
|
||||||
include:
|
|
||||||
- goarch: amd64
|
|
||||||
pkgarch: x86_64
|
|
||||||
- goarch: arm64
|
|
||||||
pkgarch: aarch64
|
|
||||||
steps:
|
|
||||||
- name: Install build dependencies
|
|
||||||
run: |
|
|
||||||
apk update
|
|
||||||
apk add --no-cache git nodejs go abuild curl sudo build-base
|
|
||||||
|
|
||||||
- name: Checkout repository
|
|
||||||
uses: actions/checkout@v4
|
|
||||||
|
|
||||||
- name: Create build user
|
|
||||||
run: |
|
|
||||||
adduser -D -G abuild build
|
|
||||||
echo "build ALL=(ALL) NOPASSWD:ALL" >> /etc/sudoers
|
|
||||||
chown -R build:abuild .
|
|
||||||
|
|
||||||
- name: Configure git safe directory
|
|
||||||
run: git config --global --add safe.directory "$PWD"
|
|
||||||
|
|
||||||
- name: Setup abuild for package signing
|
|
||||||
run: |
|
|
||||||
su build -c "abuild-keygen -a -n"
|
|
||||||
cp /home/build/.abuild/*.pub /etc/apk/keys/
|
|
||||||
|
|
||||||
- name: Prepare source
|
|
||||||
run: |
|
|
||||||
pkgver=$(echo "${{ github.ref_name }}" | sed 's/^v//')
|
|
||||||
pkgname="axolotl"
|
|
||||||
|
|
||||||
sed -i "s/pkgver=.*/pkgver=$pkgver/" packaging/alpine/APKBUILD
|
|
||||||
sed -i "s/^arch=.*/arch=\"${{ matrix.pkgarch }}\"/" packaging/alpine/APKBUILD
|
|
||||||
|
|
||||||
git archive --format=tar.gz --prefix="$pkgname-$pkgver/" -o "packaging/alpine/$pkgname-$pkgver.tar.gz" HEAD
|
|
||||||
|
|
||||||
sed -i "s|source=.*|source=\"\$pkgname-\$pkgver.tar.gz\"|" packaging/alpine/APKBUILD
|
|
||||||
chown -R build:abuild .
|
|
||||||
|
|
||||||
- name: Generate checksums
|
|
||||||
run: su build -c "cd $PWD/packaging/alpine && abuild checksum"
|
|
||||||
|
|
||||||
- name: Build package
|
|
||||||
run: su build -c "cd $PWD/packaging/alpine && GOARCH=${{ matrix.goarch }} CARCH=${{ matrix.pkgarch }} abuild -r"
|
|
||||||
|
|
||||||
- name: Publish to Gitea Registry
|
|
||||||
run: |
|
|
||||||
apk_file=$(find ~build/packages -name "*.apk" -type f | head -1)
|
|
||||||
curl --fail-with-body \
|
|
||||||
--user "${{ github.repository_owner }}:${{ secrets.ACCESS_TOKEN }}" \
|
|
||||||
--upload-file "$apk_file" \
|
|
||||||
"${{ github.server_url }}/api/packages/${{ github.repository_owner }}/alpine/edge/main"
|
|
||||||
@@ -1,15 +1,81 @@
|
|||||||
name: Build and Push Docker Container
|
name: Build and Publish Docker Image
|
||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
tags:
|
tags:
|
||||||
- 'v*'
|
- 'v*'
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
build-and-push:
|
build-apk:
|
||||||
|
runs-on:
|
||||||
|
- ubuntu-24.04
|
||||||
|
container:
|
||||||
|
image: alpine:latest
|
||||||
|
strategy:
|
||||||
|
matrix:
|
||||||
|
include:
|
||||||
|
- goarch: amd64
|
||||||
|
pkgarch: x86_64
|
||||||
|
- goarch: arm64
|
||||||
|
pkgarch: aarch64
|
||||||
|
steps:
|
||||||
|
- name: Install build dependencies
|
||||||
|
run: |
|
||||||
|
apk update
|
||||||
|
apk add --no-cache git nodejs go abuild curl sudo build-base
|
||||||
|
|
||||||
|
- name: Checkout repository
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
|
- name: Create build user
|
||||||
|
run: |
|
||||||
|
adduser -D -G abuild build
|
||||||
|
echo "build ALL=(ALL) NOPASSWD:ALL" >> /etc/sudoers
|
||||||
|
chown -R build:abuild .
|
||||||
|
|
||||||
|
- name: Configure git safe directory
|
||||||
|
run: git config --global --add safe.directory "$PWD"
|
||||||
|
|
||||||
|
- name: Setup abuild for package signing
|
||||||
|
run: |
|
||||||
|
su build -c "abuild-keygen -a -n"
|
||||||
|
cp /home/build/.abuild/*.pub /etc/apk/keys/
|
||||||
|
|
||||||
|
- name: Prepare source
|
||||||
|
run: |
|
||||||
|
pkgver=$(echo "${{ github.ref_name }}" | sed 's/^v//')
|
||||||
|
pkgname="axolotl"
|
||||||
|
|
||||||
|
sed -i "s/pkgver=.*/pkgver=$pkgver/" packaging/alpine/APKBUILD
|
||||||
|
sed -i "s/^arch=.*/arch=\"${{ matrix.pkgarch }}\"/" packaging/alpine/APKBUILD
|
||||||
|
|
||||||
|
git archive --format=tar.gz --prefix="$pkgname-$pkgver/" -o "packaging/alpine/$pkgname-$pkgver.tar.gz" HEAD
|
||||||
|
|
||||||
|
sed -i "s|source=.*|source=\"\$pkgname-\$pkgver.tar.gz\"|" packaging/alpine/APKBUILD
|
||||||
|
chown -R build:abuild .
|
||||||
|
|
||||||
|
- name: Generate checksums
|
||||||
|
run: su build -c "cd $PWD/packaging/alpine && abuild checksum"
|
||||||
|
|
||||||
|
- name: Build package
|
||||||
|
run: su build -c "cd $PWD/packaging/alpine && GOARCH=${{ matrix.goarch }} CARCH=${{ matrix.pkgarch }} abuild -r"
|
||||||
|
|
||||||
|
- name: Publish to Gitea Registry
|
||||||
|
run: |
|
||||||
|
apk_file=$(find ~build/packages -name "*.apk" -type f | head -1)
|
||||||
|
curl --fail-with-body \
|
||||||
|
--user "${{ github.repository_owner }}:${{ secrets.ACCESS_TOKEN }}" \
|
||||||
|
--upload-file "$apk_file" \
|
||||||
|
"${{ github.server_url }}/api/packages/${{ github.repository_owner }}/alpine/edge/main"
|
||||||
|
|
||||||
|
build-and-push-docker:
|
||||||
|
needs: build-apk
|
||||||
runs-on:
|
runs-on:
|
||||||
- ubuntu-24.04
|
- ubuntu-24.04
|
||||||
steps:
|
steps:
|
||||||
- name: Login to Docker Hub
|
- name: Checkout repository
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
|
- name: Login to Docker Registry
|
||||||
uses: docker/login-action@v3
|
uses: docker/login-action@v3
|
||||||
with:
|
with:
|
||||||
registry: g.eliaskohout.de
|
registry: g.eliaskohout.de
|
||||||
@@ -22,9 +88,18 @@ jobs:
|
|||||||
- name: Set up Docker Buildx
|
- name: Set up Docker Buildx
|
||||||
uses: docker/setup-buildx-action@v3
|
uses: docker/setup-buildx-action@v3
|
||||||
|
|
||||||
|
- name: Extract version
|
||||||
|
id: version
|
||||||
|
run: |
|
||||||
|
VERSION=$(echo "${{ github.ref_name }}" | sed 's/^v//')
|
||||||
|
echo "version=${VERSION}" >> "$GITHUB_OUTPUT"
|
||||||
|
|
||||||
- name: Build and push
|
- name: Build and push
|
||||||
uses: docker/build-push-action@v6
|
uses: docker/build-push-action@v6
|
||||||
with:
|
with:
|
||||||
|
context: .
|
||||||
push: true
|
push: true
|
||||||
platforms: linux/amd64,linux/arm64
|
platforms: linux/amd64,linux/arm64
|
||||||
|
build-args: |
|
||||||
|
VERSION=${{ steps.version.outputs.version }}
|
||||||
tags: "g.eliaskohout.de/eliaskohout/axolotl-server:${{gitea.ref_name}},g.eliaskohout.de/eliaskohout/axolotl-server:latest"
|
tags: "g.eliaskohout.de/eliaskohout/axolotl-server:${{gitea.ref_name}},g.eliaskohout.de/eliaskohout/axolotl-server:latest"
|
||||||
|
|||||||
+9
-19
@@ -1,25 +1,15 @@
|
|||||||
FROM golang:1.25-alpine AS builder
|
|
||||||
|
|
||||||
WORKDIR /app
|
|
||||||
|
|
||||||
ENV GOTOOLCHAIN=local
|
|
||||||
|
|
||||||
COPY src/go.mod src/go.sum ./
|
|
||||||
RUN go mod download
|
|
||||||
|
|
||||||
COPY src/ ./
|
|
||||||
|
|
||||||
RUN CGO_ENABLED=0 GOOS=$TARGETOS GOARCH=$TARGETARCH \
|
|
||||||
go build -ldflags="-s -w" -trimpath -o /ax .
|
|
||||||
|
|
||||||
FROM alpine:latest
|
FROM alpine:latest
|
||||||
|
|
||||||
RUN apk --no-cache add ca-certificates
|
ARG VERSION
|
||||||
|
ARG TARGETARCH
|
||||||
|
|
||||||
|
RUN apk --no-cache add ca-certificates && \
|
||||||
|
ARCH=$([ "$TARGETARCH" = "arm64" ] && echo aarch64 || echo x86_64) && \
|
||||||
|
wget -q "https://g.eliaskohout.de/api/packages/eliaskohout/alpine/edge/main/${ARCH}/axolotl-${VERSION}-r0.apk" \
|
||||||
|
-O /tmp/axolotl.apk && \
|
||||||
|
apk add --no-cache --allow-untrusted /tmp/axolotl.apk && \
|
||||||
|
rm /tmp/axolotl.apk
|
||||||
|
|
||||||
WORKDIR /data
|
WORKDIR /data
|
||||||
|
|
||||||
COPY --from=builder /ax /usr/local/bin/ax
|
|
||||||
|
|
||||||
EXPOSE 7000
|
EXPOSE 7000
|
||||||
|
|
||||||
ENTRYPOINT ["ax", "serve"]
|
ENTRYPOINT ["ax", "serve"]
|
||||||
|
|||||||
+47
-2
@@ -22,6 +22,48 @@ var loginCmd = &cobra.Command{
|
|||||||
}
|
}
|
||||||
base := fmt.Sprintf("http://%s:%d", rc.Host, rc.Port)
|
base := fmt.Sprintf("http://%s:%d", rc.Host, rc.Port)
|
||||||
|
|
||||||
|
sessionID := tryDeviceFlow(base)
|
||||||
|
if sessionID == "" {
|
||||||
|
sessionID = tryCallbackFlow(base)
|
||||||
|
}
|
||||||
|
|
||||||
|
pollForToken(base, sessionID)
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
// tryDeviceFlow attempts the device authorization flow. Returns a session ID
|
||||||
|
// on success, or "" if the server does not support it.
|
||||||
|
func tryDeviceFlow(base string) string {
|
||||||
|
resp, err := http.Post(base+"/auth/device/start", "application/json", nil)
|
||||||
|
if err != nil {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
defer resp.Body.Close()
|
||||||
|
if resp.StatusCode != http.StatusOK {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
var start struct {
|
||||||
|
SessionID string `json:"session_id"`
|
||||||
|
UserCode string `json:"user_code"`
|
||||||
|
VerificationURI string `json:"verification_uri"`
|
||||||
|
VerificationURIComplete string `json:"verification_uri_complete"`
|
||||||
|
}
|
||||||
|
json.NewDecoder(resp.Body).Decode(&start)
|
||||||
|
if start.SessionID == "" {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
|
uri := start.VerificationURI
|
||||||
|
if start.VerificationURIComplete != "" {
|
||||||
|
uri = start.VerificationURIComplete
|
||||||
|
}
|
||||||
|
fmt.Printf("To sign in, open this URL in any browser:\n\n %s\n\nThen enter this code: %s\n\nWaiting for authentication...\n", uri, start.UserCode)
|
||||||
|
return start.SessionID
|
||||||
|
}
|
||||||
|
|
||||||
|
// tryCallbackFlow initiates the traditional callback-based OIDC flow.
|
||||||
|
// Exits the process on failure.
|
||||||
|
func tryCallbackFlow(base string) string {
|
||||||
resp, err := http.Post(base+"/auth/start", "application/json", nil)
|
resp, err := http.Post(base+"/auth/start", "application/json", nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Fprintf(os.Stderr, "failed to contact server: %v\n", err)
|
fmt.Fprintf(os.Stderr, "failed to contact server: %v\n", err)
|
||||||
@@ -40,12 +82,16 @@ var loginCmd = &cobra.Command{
|
|||||||
}
|
}
|
||||||
|
|
||||||
fmt.Printf("Open this URL in your browser:\n\n %s\n\nWaiting for login...\n", start.URL)
|
fmt.Printf("Open this URL in your browser:\n\n %s\n\nWaiting for login...\n", start.URL)
|
||||||
|
return start.SessionID
|
||||||
|
}
|
||||||
|
|
||||||
|
// pollForToken polls the server until the login completes or times out.
|
||||||
|
func pollForToken(base, sessionID string) {
|
||||||
deadline := time.Now().Add(5 * time.Minute)
|
deadline := time.Now().Add(5 * time.Minute)
|
||||||
for time.Now().Before(deadline) {
|
for time.Now().Before(deadline) {
|
||||||
time.Sleep(2 * time.Second)
|
time.Sleep(2 * time.Second)
|
||||||
|
|
||||||
resp, err := http.Get(fmt.Sprintf("%s/auth/poll?session_id=%s", base, start.SessionID))
|
resp, err := http.Get(fmt.Sprintf("%s/auth/poll?session_id=%s", base, sessionID))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
@@ -82,7 +128,6 @@ var loginCmd = &cobra.Command{
|
|||||||
|
|
||||||
fmt.Fprintln(os.Stderr, "login timed out")
|
fmt.Fprintln(os.Stderr, "login timed out")
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
},
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
|
|||||||
+118
-8
@@ -23,16 +23,26 @@ type pendingLogin struct {
|
|||||||
serverToken string // set by callback when complete; empty while pending
|
serverToken string // set by callback when complete; empty while pending
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// pendingDeviceLogin tracks an in-progress device authorization flow.
|
||||||
|
type pendingDeviceLogin struct {
|
||||||
|
created time.Time
|
||||||
|
serverToken string // set when device token exchange completes
|
||||||
|
username string // set when device token exchange completes
|
||||||
|
err string // set if the flow fails
|
||||||
|
}
|
||||||
|
|
||||||
// authHandler owns the OIDC provider connection, the pending login store,
|
// authHandler owns the OIDC provider connection, the pending login store,
|
||||||
// and the active server-side session map.
|
// and the active server-side session map.
|
||||||
type authHandler struct {
|
type authHandler struct {
|
||||||
mu sync.Mutex
|
mu sync.Mutex
|
||||||
pending map[string]*pendingLogin // loginID → pending state
|
pending map[string]*pendingLogin // loginID → pending state
|
||||||
|
pendingDevice map[string]*pendingDeviceLogin // loginID → pending device state
|
||||||
sessions map[string]string // serverToken → username
|
sessions map[string]string // serverToken → username
|
||||||
|
|
||||||
cfg store.OIDCConfig
|
cfg store.OIDCConfig
|
||||||
provider *oidc.Provider
|
provider *oidc.Provider
|
||||||
oauth2 oauth2.Config
|
oauth2 oauth2.Config
|
||||||
|
deviceFlowAvailable bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func newAuthHandler(cfg store.OIDCConfig) (*authHandler, error) {
|
func newAuthHandler(cfg store.OIDCConfig) (*authHandler, error) {
|
||||||
@@ -43,18 +53,21 @@ func newAuthHandler(cfg store.OIDCConfig) (*authHandler, error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("OIDC provider: %w", err)
|
return nil, fmt.Errorf("OIDC provider: %w", err)
|
||||||
}
|
}
|
||||||
|
endpoint := provider.Endpoint()
|
||||||
h := &authHandler{
|
h := &authHandler{
|
||||||
pending: make(map[string]*pendingLogin),
|
pending: make(map[string]*pendingLogin),
|
||||||
|
pendingDevice: make(map[string]*pendingDeviceLogin),
|
||||||
sessions: make(map[string]string),
|
sessions: make(map[string]string),
|
||||||
cfg: cfg,
|
cfg: cfg,
|
||||||
provider: provider,
|
provider: provider,
|
||||||
oauth2: oauth2.Config{
|
oauth2: oauth2.Config{
|
||||||
ClientID: cfg.ClientID,
|
ClientID: cfg.ClientID,
|
||||||
ClientSecret: cfg.ClientSecret,
|
ClientSecret: cfg.ClientSecret,
|
||||||
Endpoint: provider.Endpoint(),
|
Endpoint: endpoint,
|
||||||
RedirectURL: cfg.PublicURL + "/auth/callback",
|
RedirectURL: cfg.PublicURL + "/auth/callback",
|
||||||
Scopes: []string{oidc.ScopeOpenID, "profile", "email", "offline_access"},
|
Scopes: []string{oidc.ScopeOpenID, "profile", "email", "offline_access"},
|
||||||
},
|
},
|
||||||
|
deviceFlowAvailable: endpoint.DeviceAuthURL != "",
|
||||||
}
|
}
|
||||||
go h.cleanup()
|
go h.cleanup()
|
||||||
return h, nil
|
return h, nil
|
||||||
@@ -68,6 +81,11 @@ func (h *authHandler) cleanup() {
|
|||||||
delete(h.pending, id)
|
delete(h.pending, id)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
for id, p := range h.pendingDevice {
|
||||||
|
if time.Since(p.created) > 15*time.Minute {
|
||||||
|
delete(h.pendingDevice, id)
|
||||||
|
}
|
||||||
|
}
|
||||||
h.mu.Unlock()
|
h.mu.Unlock()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -148,6 +166,71 @@ func (h *authHandler) callback(w http.ResponseWriter, r *http.Request) {
|
|||||||
fmt.Fprintln(w, "Login successful! You can close this tab.")
|
fmt.Fprintln(w, "Login successful! You can close this tab.")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// POST /auth/device/start → {session_id, user_code, verification_uri, verification_uri_complete}
|
||||||
|
func (h *authHandler) deviceStart(w http.ResponseWriter, r *http.Request) {
|
||||||
|
if !h.deviceFlowAvailable {
|
||||||
|
writeError(w, http.StatusNotFound, "device flow not supported by OIDC provider")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
da, err := h.oauth2.DeviceAuth(r.Context(),
|
||||||
|
oauth2.SetAuthURLParam("client_secret", h.cfg.ClientSecret),
|
||||||
|
)
|
||||||
|
if err != nil {
|
||||||
|
writeError(w, http.StatusBadGateway, "device authorization request failed: "+err.Error())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
loginID := randomToken(16)
|
||||||
|
|
||||||
|
h.mu.Lock()
|
||||||
|
h.pendingDevice[loginID] = &pendingDeviceLogin{created: time.Now()}
|
||||||
|
h.mu.Unlock()
|
||||||
|
|
||||||
|
// Exchange device code for token in the background.
|
||||||
|
go func() {
|
||||||
|
ctx, cancel := context.WithTimeout(context.Background(), 15*time.Minute)
|
||||||
|
defer cancel()
|
||||||
|
|
||||||
|
token, err := h.oauth2.DeviceAccessToken(ctx, da)
|
||||||
|
if err != nil {
|
||||||
|
h.mu.Lock()
|
||||||
|
if p := h.pendingDevice[loginID]; p != nil {
|
||||||
|
p.err = err.Error()
|
||||||
|
}
|
||||||
|
h.mu.Unlock()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
username, err := h.extractUsername(ctx, token)
|
||||||
|
if err != nil {
|
||||||
|
h.mu.Lock()
|
||||||
|
if p := h.pendingDevice[loginID]; p != nil {
|
||||||
|
p.err = "failed to identify user: " + err.Error()
|
||||||
|
}
|
||||||
|
h.mu.Unlock()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
serverToken := randomToken(32)
|
||||||
|
|
||||||
|
h.mu.Lock()
|
||||||
|
h.sessions[serverToken] = username
|
||||||
|
if p := h.pendingDevice[loginID]; p != nil {
|
||||||
|
p.serverToken = serverToken
|
||||||
|
p.username = username
|
||||||
|
}
|
||||||
|
h.mu.Unlock()
|
||||||
|
}()
|
||||||
|
|
||||||
|
writeJSON(w, map[string]string{
|
||||||
|
"session_id": loginID,
|
||||||
|
"user_code": da.UserCode,
|
||||||
|
"verification_uri": da.VerificationURI,
|
||||||
|
"verification_uri_complete": da.VerificationURIComplete,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
// GET /auth/poll?session_id=...
|
// GET /auth/poll?session_id=...
|
||||||
// Returns 202 while pending, 200 {token, username} when done, 404 if expired.
|
// Returns 202 while pending, 200 {token, username} when done, 404 if expired.
|
||||||
func (h *authHandler) poll(w http.ResponseWriter, r *http.Request) {
|
func (h *authHandler) poll(w http.ResponseWriter, r *http.Request) {
|
||||||
@@ -157,15 +240,12 @@ func (h *authHandler) poll(w http.ResponseWriter, r *http.Request) {
|
|||||||
p := h.pending[loginID]
|
p := h.pending[loginID]
|
||||||
h.mu.Unlock()
|
h.mu.Unlock()
|
||||||
|
|
||||||
if p == nil {
|
// Check callback-based flow first.
|
||||||
writeError(w, http.StatusNotFound, "session not found or expired")
|
if p != nil {
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
h.mu.Lock()
|
h.mu.Lock()
|
||||||
serverToken := p.serverToken
|
serverToken := p.serverToken
|
||||||
if serverToken != "" {
|
if serverToken != "" {
|
||||||
delete(h.pending, loginID) // consume once delivered
|
delete(h.pending, loginID)
|
||||||
}
|
}
|
||||||
h.mu.Unlock()
|
h.mu.Unlock()
|
||||||
|
|
||||||
@@ -173,9 +253,39 @@ func (h *authHandler) poll(w http.ResponseWriter, r *http.Request) {
|
|||||||
w.WriteHeader(http.StatusAccepted)
|
w.WriteHeader(http.StatusAccepted)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
username := h.lookupSession(serverToken)
|
username := h.lookupSession(serverToken)
|
||||||
writeJSON(w, map[string]string{"token": serverToken, "username": username})
|
writeJSON(w, map[string]string{"token": serverToken, "username": username})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check device flow.
|
||||||
|
h.mu.Lock()
|
||||||
|
dp := h.pendingDevice[loginID]
|
||||||
|
h.mu.Unlock()
|
||||||
|
|
||||||
|
if dp == nil {
|
||||||
|
writeError(w, http.StatusNotFound, "session not found or expired")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
h.mu.Lock()
|
||||||
|
serverToken := dp.serverToken
|
||||||
|
errMsg := dp.err
|
||||||
|
if serverToken != "" || errMsg != "" {
|
||||||
|
delete(h.pendingDevice, loginID)
|
||||||
|
}
|
||||||
|
h.mu.Unlock()
|
||||||
|
|
||||||
|
if errMsg != "" {
|
||||||
|
writeError(w, http.StatusGone, errMsg)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if serverToken == "" {
|
||||||
|
w.WriteHeader(http.StatusAccepted)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
writeJSON(w, map[string]string{"token": serverToken, "username": dp.username})
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *authHandler) extractUsername(ctx context.Context, token *oauth2.Token) (string, error) {
|
func (h *authHandler) extractUsername(ctx context.Context, token *oauth2.Token) (string, error) {
|
||||||
|
|||||||
@@ -30,6 +30,7 @@ func New(newSvc func(user string) (service.NodeService, error), oidcCfg *store.O
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
mux.HandleFunc("POST /auth/start", ah.start)
|
mux.HandleFunc("POST /auth/start", ah.start)
|
||||||
|
mux.HandleFunc("POST /auth/device/start", ah.deviceStart)
|
||||||
mux.HandleFunc("GET /auth/callback", ah.callback)
|
mux.HandleFunc("GET /auth/callback", ah.callback)
|
||||||
mux.HandleFunc("GET /auth/poll", ah.poll)
|
mux.HandleFunc("GET /auth/poll", ah.poll)
|
||||||
return withSessionAuth(ah, mux), nil
|
return withSessionAuth(ah, mux), nil
|
||||||
|
|||||||
Reference in New Issue
Block a user