feat(channels): align email oauth authorization
This commit is contained in:
@@ -22,6 +22,7 @@ import (
|
||||
"github.com/gochat/gochat/internal/repository"
|
||||
"github.com/gochat/gochat/internal/service"
|
||||
applogger "github.com/gochat/gochat/pkg/logger"
|
||||
"github.com/gochat/gochat/pkg/response"
|
||||
)
|
||||
|
||||
// MicrosoftChannelHandler handles Microsoft/Azure AD channel management.
|
||||
@@ -81,6 +82,30 @@ func (h *MicrosoftChannelHandler) Authorization(c *gin.Context) {
|
||||
c.JSON(http.StatusOK, gin.H{"authorization_url": authURL})
|
||||
}
|
||||
|
||||
// ChatwootAuthorization creates a Microsoft email OAuth authorization URL.
|
||||
// POST /api/v1/accounts/:account_id/microsoft/authorization
|
||||
func (h *MicrosoftChannelHandler) ChatwootAuthorization(c *gin.Context) {
|
||||
accountID, err := parseUintParam(c, "account_id")
|
||||
if err != nil {
|
||||
response.AbortWithStatusError(c, http.StatusBadRequest, response.ErrBadRequest, "invalid account_id")
|
||||
return
|
||||
}
|
||||
|
||||
redirectURL, err := buildChatwootEmailOAuthAuthorizationURL(accountID, chatwootEmailOAuthAuthorizationConfig{
|
||||
ClientIDEnv: "AZURE_APP_ID",
|
||||
ClientSecretEnv: "AZURE_APP_SECRET",
|
||||
AuthorizeURL: "https://login.microsoftonline.com/common/oauth2/v2.0/authorize",
|
||||
RedirectPath: "/microsoft/callback",
|
||||
Scope: "offline_access https://outlook.office.com/IMAP.AccessAsUser.All https://outlook.office.com/SMTP.Send openid profile email",
|
||||
})
|
||||
if err != nil {
|
||||
applogger.L().Errorf("Failed to build Microsoft authorization URL: %v", err)
|
||||
c.JSON(http.StatusUnprocessableEntity, gin.H{"success": false})
|
||||
return
|
||||
}
|
||||
c.JSON(http.StatusOK, gin.H{"success": true, "url": redirectURL})
|
||||
}
|
||||
|
||||
// === OAuth Callback ===
|
||||
|
||||
// MicrosoftOAuthCallbackRequest is the DTO for Microsoft OAuth callback.
|
||||
|
||||
Reference in New Issue
Block a user