Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add used env config for keys #100

Merged
merged 3 commits into from
Mar 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions docs/add_other_oauth.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@

Shield OAuth supports *Google OAuth* and *GitHub OAuth* out-of-the-box and also provides an easy way to connect any server that offers **OAuth** to it. This guide explains how to achieve this.

- [Adding New OAuth to Shield OAuth](#adding-new-oauth-to-shield-oauth)
- [Adding New OAuth To Shield OAuth](#adding-new-oauth-to-shield-oauth)
- [Setup Instruction](#setup-instruction)
- [Command Setup](#command-setup)
- [Manual Setup](#manual-setup)
- [Available Methods](#available-methods)
- [YahooOAuth Example Class](#yahoooauth-example-class)

## Setup Instruction

Expand Down Expand Up @@ -228,8 +230,8 @@ class YahooOAuth extends AbstractOAuth

$this->config = config('ShieldOAuthConfig');
$this->callback_url = base_url('oauth/' . $this->config->call_back_route);
$this->client_id = $this->config->oauthConfigs['yahoo']['client_id'];
$this->client_secret = $this->config->oauthConfigs['yahoo']['client_secret'];
$this->client_id = env('ShieldOAuthConfig.yahoo.client_id', $this->config->oauthConfigs['yahoo']['client_id']);
$this->client_secret = env('ShieldOAuthConfig.yahoo.client_secret', $this->config->oauthConfigs['yahoo']['client_secret']);
}

public function makeGoLink(string $state): string
Expand Down
9 changes: 8 additions & 1 deletion docs/install.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,14 @@ public $globals = [
## Set keys

Receive keys `client_id` and `client_secret` from each OAuth server.
To connect to any of the servers, you need to receive`client_id` and `client_secret` from them and then set them in file `app/Config/ShieldOAuthConfig`.
To connect to any of the servers, you need to receive`client_id` and `client_secret` from them and then set them in file **.env** Or `app/Config/ShieldOAuthConfig`.

We suggest that you set the keys of each service in file **.env** instead of using **app/Config/ShieldOAuthConfig**. For example, you can proceed as follows.

```env
ShieldOAuthConfig.google.client_id = Your google client_id key
ShieldOAuthConfig.google.client_secret = Your google client_secret key
```

> **Note**
> By default, there is no file `app/Config/ShieldOAuthConfig`. It is strongly recommended to set the keys to `app/Config/ShieldOAuthConfig`. This behavior will make sure that there will be no problems for the settings you have made in case of update `Shield OAuth`. To create it, you can use the following command:
Expand Down
4 changes: 2 additions & 2 deletions src/Libraries/GithubOAuth.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ public function __construct(string $token = '')

$this->config = config('ShieldOAuthConfig');
$this->callback_url = base_url('oauth/' . $this->config->call_back_route);
$this->client_id = $this->config->oauthConfigs['github']['client_id'];
$this->client_secret = $this->config->oauthConfigs['github']['client_secret'];
$this->client_id = env('ShieldOAuthConfig.github.client_id', $this->config->oauthConfigs['github']['client_id']);
$this->client_secret = env('ShieldOAuthConfig.github.client_secret', $this->config->oauthConfigs['github']['client_secret']);
}

public function makeGoLink(string $state): string
Expand Down
4 changes: 2 additions & 2 deletions src/Libraries/GoogleOAuth.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ public function __construct(string $token = '')

$this->config = config('ShieldOAuthConfig');
$this->callback_url = base_url('oauth/' . $this->config->call_back_route);
$this->client_id = $this->config->oauthConfigs['google']['client_id'];
$this->client_secret = $this->config->oauthConfigs['google']['client_secret'];
$this->client_id = env('ShieldOAuthConfig.google.client_id', $this->config->oauthConfigs['google']['client_id']);
$this->client_secret = env('ShieldOAuthConfig.google.client_secret', $this->config->oauthConfigs['google']['client_secret']);
}

public function makeGoLink(string $state): string
Expand Down
Loading