Skip to content

Commit

Permalink
feat(MicrosoftAPI): correct scope for mail auth
Browse files Browse the repository at this point in the history
  • Loading branch information
Djangss committed Dec 10, 2024
1 parent 72b4220 commit 2b09964
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 23 deletions.
2 changes: 1 addition & 1 deletion client_web/src/Components/Auth/Buttons/MicrosoftAuth.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ const MicrosoftAuth = ({ onSuccess, onError, buttonText }: MicrosoftAuthProps) =
throw new Error('MSAL not initialized');
}
const response = await msalInstance.loginPopup({
scopes: ["user.read"]
scopes: ["user.read", "Mail.Read", "Mail.ReadWrite", "Mail.Send"]
});
onSuccess(response);
} catch (error) {
Expand Down
24 changes: 24 additions & 0 deletions server/base_consumer/microsoft/api_client.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package microsoft

import (
"fmt"
)

type APIClient struct {
Token string
}

func (c *APIClient) ValidateToken() error {
// Add real token validation logic as needed
return nil
}

func InitMicrosoftAPI(token string) (*APIClient, error) {
client := &APIClient{Token: token}

if err := client.ValidateToken(); err != nil {
return nil, fmt.Errorf("invalid token: %w", err)
}

return client, nil
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ type MailListResponse struct {
}

func (c *APIClient) HandleNewEmailReceived(workflowID uint) error {
endpoint := "https://graph.microsoft.com/v1.0/me/mailFolders/Inbox/messages?$filter=isRead%20eq%20false&$top=10&$orderby=receivedDateTime%20desc"
endpoint := "https://graph.microsoft.com/v1.0/me/mailFolders/Inbox/messages?$filter=isRead%20eq%20false&$top=1&$orderby=receivedDateTime%20desc"

req, err := http.NewRequest("GET", endpoint, nil)
if err != nil {
Expand Down
21 changes: 0 additions & 21 deletions server/base_consumer/microsoft/microsoft.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,6 @@ import (
"service/utils"
)

type APIClient struct {
Token string
}

func (c *APIClient) ValidateToken() error {
// Add token validation logic here
return nil
}

func (c *APIClient) ProcessWorkflowEvent(workflowID, eventID uint) error {
var event models.Event
if err := utils.DB.First(&event, eventID).Error; err != nil {
Expand Down Expand Up @@ -45,15 +36,3 @@ func (c *APIClient) ProcessWorkflowEvent(workflowID, eventID uint) error {

return fmt.Errorf("unhandled event type: %s (%s)", event.Type, event.Name)
}

func InitMicrosoftAPI(token string) (*APIClient, error) {
client := &APIClient{
Token: token,
}

if err := client.ValidateToken(); err != nil {
return nil, fmt.Errorf("invalid token: %w", err)
}

return client, nil
}

0 comments on commit 2b09964

Please sign in to comment.