Merge branch 'master' into patch-3

This commit is contained in:
Alenros 2020-10-12 08:57:24 +03:00 committed by GitHub
commit bb6619b5c8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
28 changed files with 306 additions and 47 deletions

44
.github/ISSUE_TEMPLATE/bug.md vendored Normal file
View File

@ -0,0 +1,44 @@
---
name: 🐛 Bug Report
about: Submit a bug report to help us improve
labels: "bug"
---
## 🐛 Bug Report
(A clear and concise description of what the bug is)
## Have you spent some time to check if this issue has been raised before?
(Have you googled for a similar issue or checked our older issues for a similar bug)
## To Reproduce
(Write your steps here:)
## Expected behavior
<!--
How did you expect your project to behave?
Its fine if youre not sure your understanding is correct.
Write down what you thought would happen.
-->
(Write what you thought would happen.)
## Actual Behavior
<!--
Did something go wrong?
Is something broken, or not behaving as you expected?
Describe this section in detail, and attach screenshots if possible.
Don't only say "it doesn't work"!
-->
(Write what happened. Add screenshots, if applicable.)
## Your Environment
<!-- Include as many relevant details about the environment you experienced the bug in -->
(Write Environment, Operating system and version etc.)

17
.github/ISSUE_TEMPLATE/documentation.md vendored Normal file
View File

@ -0,0 +1,17 @@
---
name: 📚 Documentation
about: Report an issue related to documentation
labels: "documentation"
---
## 📚 Documentation
(A clear and concise description of what the issue is.)
## Have you spent some time to check if this issue has been raised before?
(Have you googled for a similar issue or checked our older issues for a similar bug)
### Have you read the [Code of Conduct](https://github.com/appwrite/appwrite/blob/master/CODE_OF_CONDUCT.md)?
(Write your answer here.)

21
.github/ISSUE_TEMPLATE/feature.md vendored Normal file
View File

@ -0,0 +1,21 @@
---
name: 🚀 Feature
about: Submit a proposal for a new feature
labels: "feature"
---
## 🚀 Feature
(A clear and concise description of what the feature is.)
## Have you spent some time to check if this issue has been raised before?
(Have you googled for a similar issue or checked our older issues for a similar bug)
### Have you read the [Code of Conduct](https://github.com/appwrite/appwrite/blob/master/CODE_OF_CONDUCT.md)?
(Write your answer here.)
## Pitch
(Please explain why this feature should be implemented and how it would be used. Add examples, if applicable.)

26
.github/PULL_REQUEST_TEMPLATE.md vendored Normal file
View File

@ -0,0 +1,26 @@
<!--
Thank you for sending the PR! We appreciate you spending the time to work on these changes.
Help us understand your motivation by explaining why you decided to make this change.
You can learn more about contributing to appwrite here: https://github.com/appwrite/appwrite/blob/master/CONTRIBUTING.md
Happy contributing!
-->
## What does this PR do?
(Provide a description of what this PR does.)
## Test Plan
(Write your test plan here. If you changed any code, please provide us with clear instructions on how you verified your changes work.)
## Related PRs and Issues
(If this PR is related to any other PR or resolves any issue or related to any issue link all related PR and issues here.)
### Have you read the [Contributing Guidelines on issues](https://github.com/appwrite/appwrite/blob/master/CONTRIBUTING.md)?
(Write your answer here.)

View File

@ -10,7 +10,7 @@
- Added option to join a user to any team from the console
- Added support for Brotli compression (@PedroCisnerosSantana, @Rohitub222)
- New UI micro-interactions and CSS fixes (@AnatoleLucet)
- UI performance & accessibility improvments (#406)
- UI performance & accessibility improvements (#406)
- New Doctor CLI to debug the Appwrite server ([#415](https://github.com/appwrite/appwrite/issues/415))
- All emails are now sent asynchronously for improved performance (@TorstenDittmann)
- Updated grid for OAuth2 providers list in the console
@ -28,11 +28,11 @@
- Fixed a UI bug preventing float values in numeric fields
- Fixed scroll positioning when moving rules order up & down
- Fixed missing validation for database documents key length (32 chars)
- Grammer fix for pt-br email templates (@rubensdemelo)
- Grammar fix for pt-br email templates (@rubensdemelo)
- Fixed update form labels and tooltips for Flutter Android apps
- Fixed missing custom scopes param for OAuth2 session create API route
- Fixed wrong JSON validation when creating and updating database documnets
- Fixed bug where max file size was limited to max of 10MB
- Fixed wrong JSON validation when creating and updating database documents
- Fixed bug where max file size was limited to a max of 10MB
- Fixed bug preventing the deletion of the project logo
- Fixed Bug when trying to overwrite OAuth cookie in the Flutter SDK
- Fixed OAuth redirect when using the self-hosted instance default success URL ([#454](https://github.com/appwrite/appwrite/issues/454))
@ -43,7 +43,7 @@
## Breaking Changes
- **Deprecated** `first` and `last` query params for documents list route in the database API
- **Deprecated** Deprectaed Pubjabi Translations ('pn')
- **Deprecated** Deprecated Punjabi Translations ('pn')
## Security
@ -142,7 +142,7 @@
- Allow non-web platform to skip origin header
- Limited console dashboard to show max 5 alerts at the same time
- Added more webhooks events
- Normailized all webhooks event names
- Normalized all webhooks event names
- Added support for SameSite cookie option with fallback cookie for old clients
- Added a new Discord OAuth adapter
- Added a new Twitch OAuth adapter

View File

@ -29,7 +29,7 @@ When `TYPE` can be:
- **fix** - a bug fix
- **refactor** - code change that neither fixes a bug nor adds a feature
**All PRs must include commit message with the changes description!**
**All PRs must include a commit message with the changes description!**
For the initial start, fork the project and use git clone command to download the repository to your computer. A standard procedure for working on an issue would be to:
@ -48,13 +48,13 @@ $ git checkout -b [name_of_your_new_branch]
$ git push origin [name_of_your_new_branch]
```
6. Submit your changes for review
5. Submit your changes for review
If you go to your repository on GitHub, you'll see a `Compare & pull request` button. Click on that button.
7. Start a Pull Request
Now submit the pull request and , click on `Create pull request`.
6. Get a code review approval / reject
7. After approval, merge your PR
8. GitHub will automatically delete the branch, after the merge is done. (they can still be restored).
6. Start a Pull Request
Now submit the pull request and click on `Create pull request`.
7. Get a code review approval/reject
8. After approval, merge your PR
9. GitHub will automatically delete the branch after the merge is done. (they can still be restored).
## Setup From Source
@ -177,9 +177,9 @@ Appwrite uses [PHP's Composer](https://getcomposer.org/) for managing dependenci
Appwrite is following the [PHP-FIG standards](https://www.php-fig.org/). Currently, we are using both PSR-0 and PSR-4 for coding standards and autoloading standards. Soon we will also review the project for support with PSR-12 (Extended Coding Style).
We use prettier for our JS coding standards and for auto-formatting our code.
We use prettier for our JS coding standards and auto-formatting our code.
## Scalability, Speed and Performance
## Scalability, Speed, and Performance
Appwrite is built to scale. Please keep in mind that the Appwrite stack can run in different environments and different scales.
@ -216,7 +216,7 @@ For us to find the right balance, please open an issue explaining your ideas bef
This will allow the Appwrite community to have sufficient discussion about the new feature value and how it fits in the product roadmap and vision.
This is also important for the Appwrite lead developers to be able to give technical input and different emphasize regarding the feature design and architecture.
This is also important for the Appwrite lead developers to be able to give technical input and different emphasis regarding the feature design and architecture.
## Build
@ -244,9 +244,9 @@ docker exec appwrite test
## Code Maintenance
We use some automation tools to help us keep a healthy code base.
We use some automation tools to help us keep a healthy codebase.
Improve PHP exeution time by using [fully-qualified function calls](https://veewee.github.io/blog/optimizing-php-performance-by-fq-function-calls/):
Improve PHP execution time by using [fully-qualified function calls](https://veewee.github.io/blog/optimizing-php-performance-by-fq-function-calls/):
```bash
php-cs-fixer fix src/ --rules=native_function_invocation --allow-risky=yes
@ -277,7 +277,7 @@ Pull requests are great, but there are many other areas where you can help Appwr
### Blogging & Speaking
Blogging, speaking about, or creating tutorials about one of Appwrites many features. Mention [@appwrite_io](https://twitter.com/appwrite_io) on Twitter and/or email team [at] appwrite [dot] io so we can give pointers and tips and help you spread the word by promoting your content on the different Appwrite communication channels. Please add your blog posts and videos of talks to our [Awesome Appwrite]() repo on GitHub.
Blogging, speaking about, or creating tutorials about one of Appwrites many features. Mention [@appwrite_io](https://twitter.com/appwrite_io) on Twitter and/or email team [at] appwrite [dot] io so we can give pointers and tips and help you spread the word by promoting your content on the different Appwrite communication channels. Please add your blog posts and videos of talks to our [Awesome Appwrite](https://github.com/appwrite/awesome-appwrite) repo on GitHub.
### Presenting at Meetups
@ -297,5 +297,5 @@ Submitting documentation updates, enhancements, designs, or bug fixes. Spelling
### Helping Someone
Searching for Appwrite on Discord, GitHub or StackOverflow and helping someone else who needs help. You can also help by reaching others how to contribute to Appwrite's repo!
Searching for Appwrite on Discord, GitHub, or StackOverflow and helping someone else who needs help. You can also help by reaching others how to contribute to Appwrite's repo!

View File

@ -14,11 +14,11 @@
[![Twitter Account](https://badgen.net/twitter/follow/appwrite_io?label=twitter)](https://twitter.com/appwrite_io)
[![Follow Appwrite on StackShare](https://badgen.net/badge/follow%20on/stackshare/blue)](https://stackshare.io/appwrite)
Appwrite is an end-to-end backend server for Web, Mobile, Native, or Backend apps packaged as a set of Docker microservices. Appwrite abstract the complexity and repetitiveness required to build a modern backend API from scratch to allow you to build secure apps faster.
Appwrite is an end-to-end backend server for Web, Mobile, Native, or Backend apps packaged as a set of Docker microservices. Appwrite abstracts the complexity and repetitiveness required to build a modern backend API from scratch and allows you to build secure apps faster.
Using Appwrite, you can easily integrate your app with user authentication & multiple sign-in methods, a database for storing and querying users and team data, storage and file management, image manipulation, schedule CRON tasks, and [more services](https://appwrite.io/docs).
[https://appwrite.io](https://appwrite.io)
Find out more at: [https://appwrite.io](https://appwrite.io)
![Appwrite](public/images/github.png)
@ -29,6 +29,7 @@ Table of Contents:
- [Windows](#windows)
- [CMD](#cmd)
- [PowerShell](#powershell)
- [Upgrade from an Older Version](#upgrade-from-an-older-version)
- [Getting Started](#getting-started)
- [Services](#services)
- [SDKs](#sdks)
@ -41,7 +42,7 @@ Table of Contents:
## Installation
Appwrite backend server is designed to run in a container environment. Running your server is as easy as running one command from your terminal. You can either run Appwrite on your localhost using docker-compose or on any other container orchestration tool like Kubernetes, Docker Swarm or Rancher.
Appwrite backend server is designed to run in a container environment. Running your server is as easy as running one command from your terminal. You can either run Appwrite on your localhost using docker-compose or on any other container orchestration tool like Kubernetes, Docker Swarm, or Rancher.
The easiest way to start running your Appwrite server is by running our docker-compose file. Before running the installation command make sure you have [Docker](https://www.docker.com/products/docker-desktop) installed on your machine:
@ -82,15 +83,19 @@ Once the Docker installation completes, go to http://localhost to access the App
For advanced production and custom installation, check out our Docker [environment variables](docs/tutorials/environment-variables.md) docs. You can also use our public [docker-compose.yml](https://appwrite.io/docker-compose.yml) file to manually set up and environment.
### Upgrade from an Older Version
If you are upgrading your Appwrite server from an older version, you should use the Appwrite migration tool once your setup is completed. For more information regarding this, check out the [Installation Docs](https://appwrite.io/docs/installation).
## Getting Started
Getting started with Appwrite is as easy as creating a new project, choosing your platform and integrating its SDK in your code. You can easily get started with your platform of choice by reading one of our Getting Started tutorials.
Getting started with Appwrite is as easy as creating a new project, choosing your platform, and integrating its SDK in your code. You can easily get started with your platform of choice by reading one of our Getting Started tutorials.
* [Getting Started for Web](https://appwrite.io/docs/getting-started-for-web)
* [Getting Started for Flutter](https://appwrite.io/docs/getting-started-for-flutter)
* [Getting Started for Server](https://appwrite.io/docs/getting-started-for-server)
* Getting Started for Android (soon...)
* Getting Started for iOS (soon...)
* Getting Started for Android (Coming soon...)
* Getting Started for iOS (Coming soon...)
### Services
@ -131,7 +136,7 @@ We truly ❤️ pull requests! If you wish to help, you can learn more about how
## Security
For security issues, kindly email us [security@appwrite.io](mailto:security@appwrite.io) instead of posting a public issue in GitHub.
For security issues, kindly email us at [security@appwrite.io](mailto:security@appwrite.io) instead of posting a public issue in GitHub.
## Follow Us

View File

@ -11,4 +11,4 @@
## Reporting a Vulnerability
For security issues, kindly email us security@appwrite.io instead of posting a public issue on GitHub.
For security issues, kindly email us at security@appwrite.io instead of posting a public issue in GitHub.

View File

@ -15,4 +15,6 @@ return [
'targeta-shopping' => __DIR__.'/credit-cards/tarjeta-shopping.png',
'union-china-pay' => __DIR__.'/credit-cards/union-china-pay.png',
'visa' => __DIR__.'/credit-cards/visa.png',
'mir' => __DIR__.'/credit-cards/mir.png',
'maestro' => __DIR__.'/credit-cards/maestro.png',
];

Binary file not shown.

After

Width:  |  Height:  |  Size: 56 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 626 KiB

View File

@ -44,7 +44,7 @@ return [
'CR' => 'Costa Rica',
'CU' => 'Kuba',
'CY' => 'Ciprus',
'CZ' => 'Tsjeggiese Republiek',
'CZ' => 'Tsjeggië',
'DE' => 'Duitsland',
'DJ' => 'Djiboeti',
'DM' => 'Dominica',
@ -195,4 +195,4 @@ return [
'ZA' => 'Suid-Afrika',
'ZM' => 'Zambia',
'ZW' => 'Zimbabwe',
];
];

View File

@ -44,7 +44,7 @@ return [
'CR' => 'Costa Rica',
'CU' => 'Cuba',
'CY' => 'Chipre',
'CZ' => 'República Checa',
'CZ' => 'Chequia',
'DE' => 'Alemania',
'DJ' => 'Yibuti',
'DM' => 'Dominica',

View File

@ -44,7 +44,7 @@ return [
'CR' => 'Kosta Rika',
'CU' => 'Kuba',
'CY' => 'Kýpros',
'CZ' => 'Kekkoslovakia',
'CZ' => 'Kekkia',
'DE' => 'Týskland',
'DJ' => 'Djibouti',
'DM' => 'Dominika',

View File

@ -44,7 +44,7 @@ return [
'CR' => 'Costa Rica',
'CU' => 'Cuba',
'CY' => 'Chypre',
'CZ' => 'République Tchèque',
'CZ' => 'Tchéquie',
'DE' => 'Allemagne',
'DJ' => 'Djibouti',
'DM' => 'Dominique',

View File

@ -13,7 +13,6 @@ return [
'AU' => 'ऑस्ट्रेलिया',
'AT' => 'ऑस्ट्रिया',
'AZ' => 'अजरबैजान',
'BI' => 'बुरुंडी',
'BE' => 'बेल्जियम',
'BJ' => 'बेनिन',

View File

@ -44,7 +44,7 @@ return [
'CR' => 'Costa Rica',
'CU' => 'Cuba',
'CY' => 'Cipro',
'CZ' => 'Repubblica Ceca',
'CZ' => 'Cechia',
'DE' => 'Germania',
'DJ' => 'Gibuti',
'DM' => 'Dominica',

View File

@ -44,7 +44,7 @@ return [
'CR' => 'Kosta Rika',
'CU' => 'Kuba',
'CY' => 'Qipro',
'CZ' => 'Republika Czecheke',
'CZ' => 'Çekia',
'DE' => 'Gjermani',
'DJ' => 'Djibouti',
'DM' => 'Dominica',
@ -195,4 +195,4 @@ return [
'ZA' => 'Afrika e Jugut',
'ZM' => 'Zambia',
'ZW' => 'Zimbabve',
];
];

View File

@ -44,7 +44,7 @@ return [
'CR' => 'Kosta Rika',
'CU' => 'Küba',
'CY' => 'Güney Kıbrıs Rum Kesimi',
'CZ' => 'Çek Cumhuriyeti',
'CZ' => 'Çekya',
'DE' => 'Almanya',
'DJ' => 'Cibuti',
'DM' => 'Dominika',

View File

@ -224,5 +224,14 @@ return [ // Ordered by ABC.
'form' => false,
'beta' => false,
'mock' => true,
],
'wordpress' => [
'name' => 'WordPress',
'developers' => 'https://developer.wordpress.com/docs/oauth2/',
'icon' => 'icon-wordpress',
'enabled' => true,
'form' => false,
'beta' => false,
'mock' => false
]
];

View File

@ -3,7 +3,7 @@
/**
* Init
*
* Inializes both Appwrite API entry point, queue workers, and CLI tasks.
* Initializes both Appwrite API entry point, queue workers, and CLI tasks.
* Set configuration, framework resources, app constants
*
*/

View File

@ -28,9 +28,9 @@
<label>Password</label>
<input name="password" type="password" autocomplete="off" placeholder="" required data-forms-password-meter pattern=".{6,}" title="Six or more characters">
<label>Password Again</label>
<label>Confirm Password</label>
<input name="passwordAgain" type="password" autocomplete="off" placeholder="" required data-forms-password-meter pattern=".{6,}" title="Six or more characters">
<button type="submit" class="btn btn-primary"><i class="fa fa-sign-in"></i> Apply</button>
</form>
</div>
</div>

View File

@ -1,3 +1,3 @@
Use this endpoint to send a verification message to your user email address to confirm they are the valid owners of that address. Both the **userId** and **secret** arguments will be passed as query parameters to the URL you have provided to be attached to the verification email. The provided URL should redirect the user back to your app and allow you to complete the verification process by verifying both the **userId** and **secret** parameters. Learn more about how to [complete the verification process](/docs/client/account#updateAccountVerification).
Use this endpoint to send a verification message to your user email address to confirm they are the valid owners of that address. Both the **userId** and **secret** arguments will be passed as query parameters to the URL you have provided to be attached to the verification email. The provided URL should redirect the user back to your app and allow you to complete the verification process by verifying both the **userId** and **secret** parameters. Learn more about how to [complete the verification process](/docs/client/account#updateVerification).
Please note that in order to avoid a [Redirect Attack](https://github.com/OWASP/CheatSheetSeries/blob/master/cheatsheets/Unvalidated_Redirects_and_Forwards_Cheat_Sheet.md), the only valid redirect URLs are the ones from domains you have set when adding your platforms in the console interface.

View File

@ -1,6 +1,6 @@
# Adding a New OAuth2 Provider
This document is part of the Appwrite contributors' guide. Before you continue reading this document make sure you have read the [Code of Conduct](../CODE_OF_CONDUCT.md) and the [Contributing Guide](../CONTRIBUTING.md).
This document is part of the Appwrite contributors' guide. Before you continue reading this document make sure you have read the [Code of Conduct](https://github.com/appwrite/appwrite/blob/master/CODE_OF_CONDUCT.md) and the [Contributing Guide](https://github.com/appwrite/appwrite/blob/master/CONTRIBUTING.md).
## Getting Started

View File

@ -22,7 +22,7 @@ This is your server private secret key that is used to encrypt all sensitive dat
### _APP_STORAGE_LIMIT
Maximun file size allowed for file upload. The deafult value is 100MB limitation. You should pass your size limit value in bytes.
Maximum file size allowed for file upload. The default value is 100MB limitation. You should pass your size limit value in bytes.
### _APP_STORAGE_ANTIVIRUS

View File

@ -26,7 +26,7 @@ Appwrite was built with scalability in mind. Appwrite can potentially scale hori
Appwrite uses a few containers to run, where each container has its job. Most of the Appwrite containers are stateless, and in order to scale them, all you need is run multiple instances of them and setup a load balancer in front of them.
If you decide to set up a load balancer for a specific container, make sure that the containers that are trying to communicate with him are accessing him trough a load balancer and not directly. All connections between Appwrite different containers are set using Docker environment variables.
If you decide to set up a load balancer for a specific container, make sure that the containers that are trying to communicate with it are accessing it through a load balancer and not directly. All connections between Appwrite different containers are set using Docker environment variables.
There are three Appwrite containers that do keep their state are the MariaDB, Redis, and InfluxDB containers that are used for storing data, cache, and stats (in this order). To scale them out, all you need to do is set up a standard cluster (just like you would with any other app using these technologies) according to your needs and performance.
@ -34,7 +34,7 @@ There are three Appwrite containers that do keep their state are the MariaDB, Re
Sending emails is hard. There are a lot of SPAM rules and configurations to master in order to set a functional SMTP server. The SMTP server that comes packaged with Appwrite is great for development but needs some work done to function well against SPAM filters. You can find some guidelines in this [tutorial]([https://www.digitalocean.com/community/tutorials/how-to-use-an-spf-record-to-prevent-spoofing-improve-e-mail-reliability](https://www.digitalocean.com/community/tutorials/how-to-use-an-spf-record-to-prevent-spoofing-improve-e-mail-reliability)).
Another **easier option** is to use an SMTP as a service product like [Sendgrid]([https://sendgrid.com/](https://sendgrid.com/)) or [Mailgun]([https://www.mailgun.com/](https://www.mailgun.com/)). You can change Appwrite SMTP settings and credentials to any 3rrd party provider you like who support SMTP integration using our [Docker environment variables]([https://github.com/appwrite/appwrite/blob/master/docs/tutorials/environment-variables.md#smtp](https://github.com/appwrite/appwrite/blob/master/docs/tutorials/environment-variables.md#smtp)). Most services offer a decent free tier to get started with.
Another **easier option** is to use an SMTP as a service product like [Sendgrid]([https://sendgrid.com/](https://sendgrid.com/)) or [Mailgun]([https://www.mailgun.com/](https://www.mailgun.com/)). You can change Appwrite SMTP settings and credentials to any 3rd party provider you like who support SMTP integration using our [Docker environment variables]([https://github.com/appwrite/appwrite/blob/master/docs/tutorials/environment-variables.md#smtp](https://github.com/appwrite/appwrite/blob/master/docs/tutorials/environment-variables.md#smtp)). Most services offer a decent free tier to get started with.
## Backups
@ -42,4 +42,4 @@ Backups are highly recommended for any production environment. Currently, there
1. Create a script to backups and restore your MariaDB Appwrite schema. Note that trying to backup MariaDB using a docker volume backup can result in a corrupted copy of your data. It is recommended to use MariaDB or MySQL built-in tools for this.
2. Create a script to backups and restore your InfluxDB stats. If you dont care much about your server stats, you can skip this.
3. Create a script to backup Appwrite storage volume. There are many [online resources]([https://blog.ssdnodes.com/blog/docker-backup-volumes/](https://blog.ssdnodes.com/blog/docker-backup-volumes/)) explaining different ways to backup a docker volume. When running on multiple servers, it is very recommended to use an attachable storage point. Some cloud providers offer integrated backups to such attachable mount, some of them are GCP, AWS, DigitalOcean, and the list continues.
3. Create a script to backup Appwrite storage volume. There are many [online resources]([https://blog.ssdnodes.com/blog/docker-backup-volumes/](https://blog.ssdnodes.com/blog/docker-backup-volumes/)) explaining different ways to backup a docker volume. When running on multiple servers, it is very recommended to use an attachable storage point. Some cloud providers offer integrated backups to such attachable mount like GCP, AWS, DigitalOcean, and the list continues.

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.7 KiB

View File

@ -0,0 +1,136 @@
<?php
namespace Appwrite\Auth\OAuth2;
use Appwrite\Auth\OAuth2;
// Reference Material
// https://developer.wordpress.com/docs/wpcc/
class WordPress extends OAuth2
{
/**
* @var array
*/
protected $user = [];
/**
* @var array
*/
protected $scopes = [
'auth',
];
/**
* @return string
*/
public function getName():string
{
return 'wordpress';
}
/**
* @return string
*/
public function getLoginURL():string
{
return 'https://public-api.wordpress.com/oauth2/authorize?'. \http_build_query([
'client_id' => $this->appID,
'redirect_uri' => $this->callback,
'response_type' => 'code',
'scope' => $this->getScopes(),
'state' => \json_encode($this->state)
]);
}
/**
* @param string $code
*
* @return string
*/
public function getAccessToken(string $code):string
{
$accessToken = $this->request(
'POST',
'https://public-api.wordpress.com/oauth2/token',
[],
\http_build_query([
'client_id' => $this->appID,
'redirect_uri' => $this->callback,
'client_secret' => $this->appSecret,
'grant_type' => 'authorization_code',
'code' => $code
])
);
$accessToken = \json_decode($accessToken, true);
if (isset($accessToken['access_token'])) {
return $accessToken['access_token'];
}
return '';
}
/**
* @param $accessToken
*
* @return string
*/
public function getUserID(string $accessToken):string
{
$user = $this->getUser($accessToken);
if (isset($user['ID'])) {
return $user['ID'];
}
return '';
}
/**
* @param $accessToken
*
* @return string
*/
public function getUserEmail(string $accessToken):string
{
$user = $this->getUser($accessToken);
if (isset($user['email']) && $user['verified']) {
return $user['email'];
}
return '';
}
/**
* @param $accessToken
*
* @return string
*/
public function getUserName(string $accessToken):string
{
$user = $this->getUser($accessToken);
if (isset($user['username'])) {
return $user['username'];
}
return '';
}
/**
* @param string $accessToken
*
* @return array
*/
protected function getUser(string $accessToken)
{
if (empty($this->user)) {
$this->user = \json_decode($this->request('GET', 'https://public-api.wordpress.com/rest/v1/me', ['Authorization: Bearer '.$accessToken]), true);
}
return $this->user;
}
}