Skip to content

Commit 7ec1772

Browse files
authored
3.x (#10)
* updated readme * optional dto params
1 parent f03cde2 commit 7ec1772

File tree

3 files changed

+52
-48
lines changed

3 files changed

+52
-48
lines changed

README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
# Steam Auth for Laravel
22
[![Latest Stable Version](https://img.shields.io/packagist/v/ilzrv/laravel-steam-auth.svg)](https://packagist.org/packages/ilzrv/laravel-steam-auth)
3-
[![Codecov](https://img.shields.io/codecov/c/github/ilzrv/laravel-steam-auth?token=MIEA87EZGP)](https://app.codecov.io/github/ilzrv/laravel-steam-auth)
43
[![Total Downloads](https://img.shields.io/packagist/dt/ilzrv/laravel-steam-auth.svg)](https://packagist.org/packages/ilzrv/laravel-steam-auth)
4+
[![GitHub Workflow Status](https://img.shields.io/github/actions/workflow/status/ilzrv/laravel-steam-auth/tests.yml)](https://github.com/ilzrv/laravel-steam-auth/actions/workflows/tests.yml)
5+
[![Codecov](https://img.shields.io/codecov/c/github/ilzrv/laravel-steam-auth?token=MIEA87EZGP)](https://app.codecov.io/github/ilzrv/laravel-steam-auth)
56
[![License](https://img.shields.io/github/license/ilzrv/laravel-steam-auth.svg)](https://packagist.org/packages/ilzrv/laravel-steam-auth)
67

78
Package allows you to implement Steam authentication in your Laravel project.
@@ -113,6 +114,7 @@ use Illuminate\Auth\AuthManager;
113114
use Illuminate\Http\RedirectResponse;
114115
use Illuminate\Http\Request;
115116
use Illuminate\Routing\Redirector;
117+
use Ilzrv\LaravelSteamAuth\Exceptions\Authentication\SteamResponseNotValidAuthenticationException;
116118
use Ilzrv\LaravelSteamAuth\Exceptions\Validation\ValidationException;
117119
use Ilzrv\LaravelSteamAuth\SteamAuthenticator;
118120
use Ilzrv\LaravelSteamAuth\SteamUserDto;
@@ -134,7 +136,7 @@ final class SteamAuthController
134136

135137
try {
136138
$steamAuthenticator->auth();
137-
} catch (ValidationException) {
139+
} catch (ValidationException|SteamResponseNotValidAuthenticationException) {
138140
return $redirector->to(
139141
$steamAuthenticator->buildAuthUrl()
140142
);

src/SteamAuthenticator.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,9 @@ public function auth(): void
5151
$contents = $response->getBody()->getContents();
5252

5353
if (preg_match("#is_valid\s*:\s*true#i", $contents) !== 1) {
54-
throw new SteamResponseNotValidAuthenticationException();
54+
throw new SteamResponseNotValidAuthenticationException(
55+
sprintf('Steam response contains invalid content: "%s"', $contents)
56+
);
5557
}
5658

5759
$query = $this->parseUriQueryString();

src/SteamUserDto.php

Lines changed: 45 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -8,21 +8,21 @@ final class SteamUserDto
88
{
99
private function __construct(
1010
private readonly string $steamId,
11-
private readonly int $communityVisibilityState,
12-
private readonly int $profileState,
13-
private readonly string $personaName,
14-
private readonly int $commentPermission,
15-
private readonly string $profileUrl,
16-
private readonly string $avatar,
17-
private readonly string $avatarMedium,
18-
private readonly string $avatarFull,
19-
private readonly string $avatarHash,
20-
private readonly int $lastLogoff,
21-
private readonly int $personaState,
22-
private readonly string $primaryClanId,
23-
private readonly int $timeCreated,
24-
private readonly int $personaStateFlags,
25-
private readonly string $locCountryCode,
11+
private readonly ?int $communityVisibilityState,
12+
private readonly ?int $profileState,
13+
private readonly ?string $personaName,
14+
private readonly ?int $commentPermission,
15+
private readonly ?string $profileUrl,
16+
private readonly ?string $avatar,
17+
private readonly ?string $avatarMedium,
18+
private readonly ?string $avatarFull,
19+
private readonly ?string $avatarHash,
20+
private readonly ?int $lastLogoff,
21+
private readonly ?int $personaState,
22+
private readonly ?string $primaryClanId,
23+
private readonly ?int $timeCreated,
24+
private readonly ?int $personaStateFlags,
25+
private readonly ?string $locCountryCode,
2626
private readonly ?int $playerLevel,
2727
) {
2828
}
@@ -31,21 +31,21 @@ public static function create(array $data): self
3131
{
3232
return new self(
3333
steamId: $data['steamid'],
34-
communityVisibilityState: $data['communityvisibilitystate'],
35-
profileState: $data['profilestate'],
36-
personaName: $data['personaname'],
37-
commentPermission: $data['commentpermission'],
38-
profileUrl: $data['profileurl'],
39-
avatar: $data['avatar'],
40-
avatarMedium: $data['avatarmedium'],
41-
avatarFull: $data['avatarfull'],
42-
avatarHash: $data['avatarhash'],
43-
lastLogoff: $data['lastlogoff'],
44-
personaState: $data['personastate'],
45-
primaryClanId: $data['primaryclanid'],
46-
timeCreated: $data['timecreated'],
47-
personaStateFlags: $data['personastateflags'],
48-
locCountryCode: $data['loccountrycode'],
34+
communityVisibilityState: $data['communityvisibilitystate'] ?? null,
35+
profileState: $data['profilestate'] ?? null,
36+
personaName: $data['personaname'] ?? null,
37+
commentPermission: $data['commentpermission'] ?? null,
38+
profileUrl: $data['profileurl'] ?? null,
39+
avatar: $data['avatar'] ?? null,
40+
avatarMedium: $data['avatarmedium'] ?? null,
41+
avatarFull: $data['avatarfull'] ?? null,
42+
avatarHash: $data['avatarhash'] ?? null,
43+
lastLogoff: $data['lastlogoff'] ?? null,
44+
personaState: $data['personastate'] ?? null,
45+
primaryClanId: $data['primaryclanid'] ?? null,
46+
timeCreated: $data['timecreated'] ?? null,
47+
personaStateFlags: $data['personastateflags'] ?? null,
48+
locCountryCode: $data['loccountrycode'] ?? null,
4949
playerLevel: $data['player_level'] ?? null,
5050
);
5151
}
@@ -55,77 +55,77 @@ public function getSteamId(): string
5555
return $this->steamId;
5656
}
5757

58-
public function getCommunityVisibilityState(): int
58+
public function getCommunityVisibilityState(): ?int
5959
{
6060
return $this->communityVisibilityState;
6161
}
6262

63-
public function getProfileState(): int
63+
public function getProfileState(): ?int
6464
{
6565
return $this->profileState;
6666
}
6767

68-
public function getPersonaName(): string
68+
public function getPersonaName(): ?string
6969
{
7070
return $this->personaName;
7171
}
7272

73-
public function getCommentPermission(): int
73+
public function getCommentPermission(): ?int
7474
{
7575
return $this->commentPermission;
7676
}
7777

78-
public function getProfileUrl(): string
78+
public function getProfileUrl(): ?string
7979
{
8080
return $this->profileUrl;
8181
}
8282

83-
public function getAvatar(): string
83+
public function getAvatar(): ?string
8484
{
8585
return $this->avatar;
8686
}
8787

88-
public function getAvatarMedium(): string
88+
public function getAvatarMedium(): ?string
8989
{
9090
return $this->avatarMedium;
9191
}
9292

93-
public function getAvatarFull(): string
93+
public function getAvatarFull(): ?string
9494
{
9595
return $this->avatarFull;
9696
}
9797

98-
public function getAvatarHash(): string
98+
public function getAvatarHash(): ?string
9999
{
100100
return $this->avatarHash;
101101
}
102102

103-
public function getLastLogoff(): int
103+
public function getLastLogoff(): ?int
104104
{
105105
return $this->lastLogoff;
106106
}
107107

108-
public function getPersonaState(): int
108+
public function getPersonaState(): ?int
109109
{
110110
return $this->personaState;
111111
}
112112

113-
public function getPrimaryClanId(): string
113+
public function getPrimaryClanId(): ?string
114114
{
115115
return $this->primaryClanId;
116116
}
117117

118-
public function getTimeCreated(): int
118+
public function getTimeCreated(): ?int
119119
{
120120
return $this->timeCreated;
121121
}
122122

123-
public function getPersonaStateFlags(): int
123+
public function getPersonaStateFlags(): ?int
124124
{
125125
return $this->personaStateFlags;
126126
}
127127

128-
public function getLocCountryCode(): string
128+
public function getLocCountryCode(): ?string
129129
{
130130
return $this->locCountryCode;
131131
}

0 commit comments

Comments
 (0)