Merge pull request #250 from stanley-cheung/add_php_google_auth_example
Add PHP Google Auth example
This commit is contained in:
commit
2285e081a9
|
|
@ -174,3 +174,24 @@ if (authorization.IsCreateScopedRequired)
|
||||||
var client = new Greeter.GreeterClient(channel,
|
var client = new Greeter.GreeterClient(channel,
|
||||||
new StubConfiguration(OAuth2InterceptorFactory.Create(credential)));
|
new StubConfiguration(OAuth2InterceptorFactory.Create(credential)));
|
||||||
```
|
```
|
||||||
|
|
||||||
|
###Authenticating with Google (PHP)
|
||||||
|
```php
|
||||||
|
// Base case - No encryption/authorization
|
||||||
|
$client = new helloworld\GreeterClient(
|
||||||
|
new Grpc\BaseStub('localhost:50051', []));
|
||||||
|
...
|
||||||
|
|
||||||
|
// Authenticating with Google
|
||||||
|
// the environment variable "GOOGLE_APPLICATION_CREDENTIALS" needs to be set
|
||||||
|
$scope = "https://www.googleapis.com/auth/grpc-testing";
|
||||||
|
$auth = Google\Auth\ApplicationDefaultCredentials::getCredentials($scope);
|
||||||
|
$opts = [
|
||||||
|
'credentials' => Grpc\Credentials::createSsl(file_get_contents('ca.pem'));
|
||||||
|
'update_metadata' => $auth->getUpdateMetadataFunc(),
|
||||||
|
];
|
||||||
|
|
||||||
|
$client = new helloworld\GreeterClient(
|
||||||
|
new Grpc\BaseStub('localhost:50051', $opts));
|
||||||
|
|
||||||
|
```
|
||||||
|
|
|
||||||
|
|
@ -11,6 +11,7 @@
|
||||||
"require": {
|
"require": {
|
||||||
"php": ">=5.5.0",
|
"php": ">=5.5.0",
|
||||||
"datto/protobuf-php": "dev-master",
|
"datto/protobuf-php": "dev-master",
|
||||||
|
"google/auth": "dev-master",
|
||||||
"grpc/grpc": "dev-master"
|
"grpc/grpc": "dev-master"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue