Skip to content

Conversation

@elboletaire
Copy link
Member

refs #286

@elboletaire elboletaire changed the title refactor(auth): oauth improvements refactor(oauth): improvements Nov 6, 2025
@github-actions
Copy link

github-actions bot commented Nov 6, 2025

This PR introduces the following changes in the API documentation:

diff --git a/docs/swagger.yaml b/docs/swagger.yaml
index 29739d4..c53c7e6 100644
--- a/docs/swagger.yaml
+++ b/docs/swagger.yaml
@@ -282,6 +282,21 @@ definitions:
         format: hex
         type: string
     type: object
+  apicommon.OAuthLinkRequest:
+    properties:
+      address:
+        description: The address of the user
+        type: string
+      oauthSignature:
+        description: The signature made by the OAuth service on top of the user email
+        type: string
+      provider:
+        description: OAuth provider name (google, github, facebook)
+        type: string
+      userOAuthSignature:
+        description: The signature made by the user on top of the oauth signature
+        type: string
+    type: object
   apicommon.OAuthLoginResponse:
     properties:
       expirity:
@@ -883,6 +898,9 @@ definitions:
       firstName:
         description: User's first name
         type: string
+      hasPassword:
+        description: Whether the user has a password set (true if not OAuth-only)
+        type: boolean
       id:
         description: User ID as generated by the backend
         type: integer
@@ -897,6 +915,12 @@ definitions:
       password:
         description: User's password (not returned in responses)
         type: string
+      providers:
+        description: List of OAuth providers linked to this account (e.g., ["google",
+          "github"])
+        items:
+          type: string
+        type: array
       verified:
         description: Whether the user's email is verified
         type: boolean
@@ -1278,8 +1302,7 @@ paths:
     get:
       consumes:
       - application/json
-      description: Get the list of organization addresses where the user has write
-        access
+      description: Get the list of organization addresses the user belongs to
       produces:
       - application/json
       responses:
@@ -1297,7 +1320,7 @@ paths:
             $ref: '#/definitions/errors.Error'
       security:
       - BearerAuth: []
-      summary: Get writable organization addresses
+      summary: Get a list of addresses the user belongs to
       tags:
       - auth
   /auth/login:
@@ -1330,6 +1353,79 @@ paths:
       summary: Login to get a JWT token
       tags:
       - auth
+  /auth/oauth/link:
+    post:
+      consumes:
+      - application/json
+      description: Link an OAuth provider to an existing authenticated account
+      parameters:
+      - description: OAuth link information
+        in: body
+        name: request
+        required: true
+        schema:
+          $ref: '#/definitions/apicommon.OAuthLinkRequest'
+      produces:
+      - application/json
+      responses:
+        "200":
+          description: OK
+          schema:
+            type: string
+        "400":
+          description: Invalid provider or provider already linked
+          schema:
+            $ref: '#/definitions/errors.Error'
+        "401":
+          description: Unauthorized or signature verification failed
+          schema:
+            $ref: '#/definitions/errors.Error'
+        "500":
+          description: Internal server error
+          schema:
+            $ref: '#/definitions/errors.Error'
+      security:
+      - BearerAuth: []
+      summary: Link OAuth provider to account
+      tags:
+      - auth
+  /auth/oauth/unlink/{provider}:
+    delete:
+      consumes:
+      - application/json
+      description: Unlink an OAuth provider from an authenticated account. Cannot
+        unlink the last authentication method.
+      parameters:
+      - description: OAuth provider name (google, github, facebook)
+        in: path
+        name: provider
+        required: true
+        type: string
+      produces:
+      - application/json
+      responses:
+        "200":
+          description: OK
+          schema:
+            type: string
+        "400":
+          description: Invalid provider, provider not linked, or cannot unlink last
+            auth method
+          schema:
+            $ref: '#/definitions/errors.Error'
+        "401":
+          description: Unauthorized
+          schema:
+            $ref: '#/definitions/errors.Error'
+        "500":
+          description: Internal server error
+          schema:
+            $ref: '#/definitions/errors.Error'
+      security:
+      - BearerAuth: []
+      summary: Unlink OAuth provider from account
+      tags:
+      - auth
   /auth/refresh:
     post:
       consumes:

@coveralls
Copy link

coveralls commented Nov 6, 2025

Pull Request Test Coverage Report for Build 19175006934

Details

  • 93 of 213 (43.66%) changed or added relevant lines in 4 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage decreased (-0.4%) to 60.12%

Changes Missing Coverage Covered Lines Changed/Added Lines %
api/auth.go 34 42 80.95%
api/users.go 2 12 16.67%
migrations/0005_update_user_validator.go 40 81 49.38%
migrations/0004_add_oauth_providers.go 17 78 21.79%
Totals Coverage Status
Change from base Build 19137423129: -0.4%
Covered Lines: 6392
Relevant Lines: 10632

💛 - Coveralls

@elboletaire elboletaire force-pushed the f/multiple-oauth-providers-286 branch 3 times, most recently from de6cac8 to b9bbd1a Compare November 7, 2025 16:45
- Adds a migration to make the user.password field non mandatory
- Also creates the "oauth" object field for any existing user
- The oauth login/signup endpoint now expects a "provider" key with the
  provider used (either google, facebook or github right now)
- Added some extra useful information to the provider because why not
- The down migration takes into consideration possible existing OAuth
  users with the new format, moving their new password to the old
  "password" field, to give some kind of backwards compatibility (and
  also to not break the migrations)

refs #286
- Added a hasPassword field to the profile (/me) response
- Also added a providers field to the same profile response with an
  array of already linked providers

refs #286
@elboletaire elboletaire force-pushed the f/multiple-oauth-providers-286 branch from cd4e364 to a3af981 Compare November 7, 2025 17:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants