Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Invalid scope on email sending #1566

Closed
ShahbozHalim opened this issue Aug 6, 2024 · 2 comments
Closed

Invalid scope on email sending #1566

ShahbozHalim opened this issue Aug 6, 2024 · 2 comments
Assignees
Labels
no-recent-activity status:waiting-for-author-feedback Issue that we've responded but needs author feedback to close type:question An issue that's a question

Comments

@ShahbozHalim
Copy link

ShahbozHalim commented Aug 6, 2024

Describe the bug

  "error" => "invalid_scope"
  "error_description" => "AADSTS1002012: The provided value for scope Mail.Send is not valid. Client credential flows must have a scope value with /.default suffixed to the resource identifier (application ID URI). Trace ID: 185a6ac5-d7dc-4421-b30b-502c4ba77300 Correlation ID: 43a59ceb-d5f5-4670-8191-04ba34594750 Timestamp: 2024-08-06 12:36:17Z"
  "error_codes" => array:1 [
    0 => 1002012
  ]
  "timestamp" => "2024-08-06 12:36:17Z"
  "trace_id" => "185a6ac5-d7dc-4421-b30b-502c4ba77300"
  "correlation_id" => "43a59ceb-d5f5-4670-8191-04ba34594750"

Expected behavior

I want to send an email

How to reproduce

$tokenRequestContext = new ClientCredentialContext(
            config('azura.tenant_id'),
            config('azura.client_id'),
            config('azura.client_secret'),
        );
    $scopes = ['Mail.Send'];
    $graphServiceClient = new GraphServiceClient($tokenRequestContext, $scopes);

    $sender = new EmailAddress();
    $sender->setAddress('noreply@alif.tj');
    $sender->setName('noreply');
    $fromRecipient = new Recipient();
    $fromRecipient->setEmailAddress($sender);

    $recipients = [];

    $recipientEmail = new EmailAddress();
    $recipientEmail->setAddress('shahbaz@alif.tj');
    $recipientEmail->setName('Jane Doe');
    $toRecipient = new Recipient();
    $toRecipient->setEmailAddress($recipientEmail);
    $recipients[] = $toRecipient;

    $emailBody = new ItemBody();
    $emailBody->setContent('Dummy content');
    $emailBody->setContentType(new BodyType(BodyType::TEXT));

    $message = new Message();
    $message->setSubject('Test Email');
    $message->setFrom($fromRecipient);
    $message->setToRecipients($recipients);
    $message->setBody($emailBody);

    $requestBody = new SendMailPostRequestBody();
    $requestBody->setMessage($message);

    $response = $graphServiceClient->me()->sendMail()->post($requestBody)->wait();

SDK Version

2.12

Latest version known to work for scenario above?

No response

Known Workarounds

No response

Debug output

Click to expand log ```
</details>


### Configuration

_No response_

### Other information

_No response_
@ShahbozHalim ShahbozHalim added status:waiting-for-triage An issue that is yet to be reviewed or assigned type:bug A broken experience labels Aug 6, 2024
@Ndiritu Ndiritu self-assigned this Aug 8, 2024
@Ndiritu Ndiritu removed the status:waiting-for-triage An issue that is yet to be reviewed or assigned label Aug 8, 2024
@Ndiritu
Copy link
Contributor

Ndiritu commented Aug 9, 2024

Hi @ShahbozHalim
When using the ClientSecretCredential/application permissions, ideally you should grant Mail.Read permissions to your app as shown here then pass the .default scope or leave the param empty in the constructor (which defaults to https://graph.microsoft.com/.default)

Let me know if this works

@Ndiritu Ndiritu added type:question An issue that's a question status:waiting-for-author-feedback Issue that we've responded but needs author feedback to close and removed type:bug A broken experience labels Aug 9, 2024
Copy link
Contributor

This issue has been automatically marked as stale because it has been marked as requiring author feedback but has not had any activity for 4 days. It will be closed if no further activity occurs within 3 days of this comment.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
no-recent-activity status:waiting-for-author-feedback Issue that we've responded but needs author feedback to close type:question An issue that's a question
Projects
None yet
Development

No branches or pull requests

2 participants