Skip to content

Commit 11556bc

Browse files
committed
Fix Tests, Add Docs
1 parent d8a8221 commit 11556bc

File tree

2 files changed

+52
-5
lines changed

2 files changed

+52
-5
lines changed

docs/v3/msgraph/queues.md

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
---
2+
title: Queues
3+
---
4+
5+
If you want to use `MsGraph` within a job or command, you can use the `login` method to authenticate the user. Make sure to pass the user model to the `login` method. The User needs to have the `access_token` and `refresh_token` stored in the database.
6+
7+
```php
8+
MsGraph::login(User:find(1));
9+
10+
MsGraph->get('me');
11+
```
12+
13+
Example Job:
14+
15+
```php
16+
<?php
17+
18+
namespace App\Jobs;
19+
20+
use App\Models\User;
21+
// ...
22+
23+
class ExampleJob implements ShouldQueue
24+
{
25+
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
26+
27+
public $user;
28+
29+
/**
30+
* Create a new job instance.
31+
*/
32+
public function __construct(User $user)
33+
{
34+
$this->user = $user;
35+
}
36+
37+
/**
38+
* Execute the job.
39+
*/
40+
public function handle(): void
41+
{
42+
MsGraph::login($this->user);
43+
44+
$me = MsGraph::get("me");
45+
}
46+
}
47+
```

src/MsGraph.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -185,11 +185,11 @@ public function getAccessToken(?string $id = null, bool $redirectWhenNotConnecte
185185
$token = $this->getTokenData($id);
186186
$id = $this->getUserId($id);
187187

188-
// if ($redirectWhenNotConnected) {
189-
// if (! $this->isConnected()) {
190-
// return redirect()->away(config('msgraph.redirectUri'));
191-
// }
192-
// }
188+
if ($this->getUser() === null && $redirectWhenNotConnected) {
189+
if (! $this->isConnected()) {
190+
return redirect()->away(config('msgraph.redirectUri'));
191+
}
192+
}
193193

194194
if ($token === null) {
195195
return null;

0 commit comments

Comments
 (0)