Created
October 19, 2023 19:37
-
-
Save wess/97cb02007efcc28dbdbb368232b6815a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace Appwrite\Auth; | |
class Metamask extends OAuth2 | |
{ | |
/** | |
* @return string | |
*/ | |
public function getName(): string | |
{ | |
return 'metamask'; | |
} | |
/** | |
* For Metamask, there isn't a traditional login URL. Instead, you'll rely on client-side logic | |
* to trigger the Metamask popup. Return an empty string or perhaps some client-side URL to handle it. | |
* | |
* @return string | |
*/ | |
public function getLoginURL(): string | |
{ | |
return ''; | |
} | |
/** | |
* In the case of Metamask, the "code" would be a signed message. We'd need the original | |
* message and the Ethereum address too, to verify. | |
* | |
* @param string $code | |
* @return array | |
*/ | |
protected function getTokens(string $code): array | |
{ | |
// Note: this is not how Metamask authentication really works. | |
// Just a mock implementation for the sake of this example. | |
return [ | |
'access_token' => $code, // Just return the signed message as an "access token" | |
'expires_in' => 3600, // Just a mock value. | |
]; | |
} | |
// For the following methods, we're using mock implementations. | |
// In a real-world scenario, you'd interact with the Ethereum blockchain or use a service. | |
public function refreshTokens(string $refreshToken): array | |
{ | |
return [ | |
'access_token' => $refreshToken, | |
'expires_in' => 3600, | |
]; | |
} | |
public function getUserID(string $accessToken): string | |
{ | |
// Normally, with Metamask, the Ethereum address would act as a user ID. | |
return '0x...'; // Mock Ethereum address | |
} | |
public function getUserEmail(string $accessToken): string | |
{ | |
// Metamask doesn't provide emails. Return a mock or an empty string. | |
return ''; | |
} | |
public function isEmailVerified(string $accessToken): bool | |
{ | |
// Metamask doesn't provide emails. | |
return false; | |
} | |
public function getUserName(string $accessToken): string | |
{ | |
// Metamask doesn't provide usernames. Return a mock or an empty string. | |
return ''; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment