dcblogdev / laravel-microsoft-graph

Laravel package for Microsoft Graph API (Microsoft365)

Home Page:https://dcblog.dev/docs/laravel-microsoft-graph

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

MsGraphAdmin unable to get AccessToken

ChrisToxz opened this issue · comments

I'm trying to send mails as admin with the following code.

MsGraphAdmin::emails()
            ->userid()//userPrincipalName
            ->to()
            ->subject()
            ->body()
            ->send();

I get the following error:

Cache-Control: no-cache, private
Date:          Mon, 17 Oct 2022 19:18:13 GMT
Location:      https://xx/connect

<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8" />
        <meta http-equiv="refresh" content="0;url='https://xx/connect'" />

        <title>Redirecting to https://xx/connect</title>
    </head>
    <body>
        Redirecting to <a href="https://xx/connect">https://spnl.eu/connect</a>.
    </body>
</html>" is not valid header value in C:\laragon\www\vendor\guzzlehttp\psr7\src\MessageTrait.php:261

In the guzzle method it tries to add the access token by $this->getAccessToken(), however this returns a redirection to the connect page.

Also not sure how the 'id' is passed trough in MsGraphAdmin.php

     * Return authenticated access token or request new token when expired.
     *** @param  $id integer - id of the user**
     * @param  $returnNullNoAccessToken null when set to true return null
     * @return return string access token
     */
    public function getAccessToken($returnNullNoAccessToken = null)
    {
        //use id if passed otherwise use logged-in user
        $token = MsGraphToken::where('user_id', null)->first();

Working on a fix, will do a pull request soon.