我已经设置了一个测试Google云端点api并让它运行得非常快.它运行良好,使用iOS模拟器中的测试应用程序,并使用Google的API Explorer.API目前对所有人开放,无需身份验证.
我想:设置一个API密钥或系统凭证,可以由应用程序使用,以确保它可以单独访问api - 所有其他人都被拒绝.
在该方法谷歌端点验证文档(1)是创建使用OAuth 2.0用户端ID 谷歌开发者控制台(2).所以我为类型为iOS的已安装应用程序创建了一个ID.到现在为止还挺好.
在应用程序中,GTLService对象看起来像这样......
-(GTLServiceDemogaeapi *)myApiService {
GTMOAuth2Authentication *auth = [[GTMOAuth2Authentication alloc] init];
auth.clientID = @"10???????????????????ie.apps.googleusercontent.com";
auth.clientSecret = @"z????????????3";
auth.scope = @"https://www.googleapis.com/auth/userinfo.email";
static GTLServiceDemogaeapi *service = nil;
if (!service) {
service = [[GTLServiceDemogaeapi alloc] init];
service.authorizer = auth;
service.retryEnabled = YES;
[GTMHTTPFetcher setLoggingEnabled:YES];
}
return service;
}
Run Code Online (Sandbox Code Playgroud)
在GAE上我已经指定了(allowed_client_ids并在方法中添加了用户检查...
@endpoints.api(name='demogaeapi', version='v1',
allowed_client_ids=['10?????????????ie.apps.googleusercontent.com',
endpoints.API_EXPLORER_CLIENT_ID],
scopes=[endpoints.EMAIL_SCOPE],
description='My Demo API')
class MyApi(remote.Service):
@TestModel.method(path='testmodel/{id}', name='testmodel.insert', http_method='POST')
def testModelInsert(self, test_model):
current_user = endpoints.get_current_user() …Run Code Online (Sandbox Code Playgroud) python google-app-engine google-cloud-endpoints endpoints-proto-datastore