Skip to content

Commit b24733e

Browse files
committed
auth samples: implicit, explicit, gce, gae
1 parent 4cd4703 commit b24733e

18 files changed

+7834
-0
lines changed

auth/appengine/app.php

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
2+
/**
3+
* Copyright 2016 Google Inc.
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
# [START auth_cloud_explicit_app_engine]
19+
use Google\Auth\Credentials\AppIdentityCredentials;
20+
use Google\Cloud\Storage\StorageClient;
21+
use Silex\Application;
22+
use Symfony\Component\HttpFoundation\Request;
23+
24+
// create the Silex application
25+
$app = new Application();
26+
27+
$app->get('/', function () use ($app) {
28+
# Explicitly use service account credentials by using App Engine credentials.
29+
# Learn more about scopes at https://cloud.google.com/storage/docs/authentication#oauth-scopes
30+
$projectId = $app['project_id'];
31+
$scope = 'https://www.googleapis.com/auth/devstorage.read_only';
32+
$gae = new AppIdentityCredentials($scope);
33+
$config = [
34+
'projectId' => $projectId,
35+
'credentialsFetcher' => $gae,
36+
];
37+
$storage = new StorageClient($config);
38+
39+
# Make an authenticated API request (listing storage buckets)
40+
$buckets = $storage->buckets();
41+
# [END auth_cloud_explicit_compute_engine]
42+
43+
$content = '';
44+
foreach ($buckets as $bucket) {
45+
$content .= $bucket->name();
46+
$content .= ', ';
47+
}
48+
$content = substr($content, 0, -2);
49+
$escapedContent = htmlspecialchars($content);
50+
$html = "

Storage Buckets

"
;
51+
if ($content) {
52+
$html .= "

Your Cloud Storage buckets:

$escapedContent

"
;
53+
}
54+
return $html;
55+
});
56+
57+
return $app;
58+

auth/appengine/app.yaml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
runtime: php55
2+
api_version: 1
3+
threadsafe: true
4+
5+
handlers:
6+
- url: /.*
7+
script: index.php
8+
9+
env_variables:
10+
GCLOUD_PROJECT: 'php-auth-samples'

auth/appengine/composer.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"require": {
3+
"silex/silex": "^1.3",
4+
"google/cloud-storage": "^1.0"
5+
},
6+
"require-dev": {
7+
"symfony/browser-kit": "^3.0",
8+
"google/cloud-tools":"^0.6"
9+
}
10+
}

0 commit comments

Comments
 (0)