App Engine SDK 1.8.4 release.
[gae.git] / java / src / main / com / google / appengine / api / appidentity / AppIdentityService.java
blob75eb7afe6d87c3d99f19a4712d6df547a415ea65
1 // Copyright 2011 Google Inc. All rights reserved.
2 package com.google.appengine.api.appidentity;
4 import java.io.Serializable;
5 import java.util.Collection;
6 import java.util.Date;
8 /**
9 * The {@code AppIdentityService} allows you to sign arbitrary byte
10 * array using per app private key maintained by App Egnine, and also
11 * you can retrieve a list of public certificates which can be used to
12 * verify the signature.
14 * <p>App Engine is responsible for maintaining per application
15 * private key. AppEngine will keep rotating private keys
16 * periodically. App Engine never gives these private keys to outside.
18 * <p>Since private keys are rotated periodically,
19 * {@link #getPublicCertificatesForApp} could return a list of public
20 * certificates, it's caller's responsibility to try these
21 * certificates one by one when doing signature verification.
24 public interface AppIdentityService {
26 /**
27 * {@code SigningResult} is returned by signForApp, which contains
28 * signing key name and signature.
30 public static class SigningResult {
31 private final String keyName;
32 private byte[] signature;
34 public SigningResult(String keyName, byte[] signature) {
35 this.keyName = keyName;
36 this.signature = signature;
39 public String getKeyName() {
40 return keyName;
43 public byte[] getSignature() {
44 return signature;
48 /**
49 * {@code GetAccessTokenResult} is returned by getAccessToken. It
50 * contains the access token and the expiration time for the token.
52 public static class GetAccessTokenResult implements Serializable {
53 private static final long serialVersionUID = 1311635361L;
54 private final String accessToken;
55 private final Date expirationTime;
57 public GetAccessTokenResult(String accessToken, Date expirationTime) {
58 this.accessToken = accessToken;
59 this.expirationTime = expirationTime;
62 public String getAccessToken() {
63 return accessToken;
66 public Date getExpirationTime() {
67 return expirationTime;
71 /**
72 * Class holding the results of parsing a full application id into its constituent parts.
73 * @see #parseFullAppId
75 public static final class ParsedAppId {
76 private final String partition;
77 private final String domain;
78 private final String id;
80 ParsedAppId(String partition, String domain, String id) {
81 this.partition = partition;
82 this.domain = domain;
83 this.id = id;
86 /** Returns the partition the application runs in. */
87 public String getPartition() {
88 return partition;
91 /** Returns the application's domain or the empty string if no domain. */
92 public String getDomain() {
93 return domain;
96 /** Returns the display application id. */
97 public String getId() {
98 return id;
103 * Requests to sign arbitrary byte array using per app private key.
105 * @param signBlob string blob.
106 * @return a SigningResult object which contains signing key name and
107 * signature.
108 * @throws AppIdentityServiceFailureException
110 SigningResult signForApp(byte[] signBlob);
113 * Retrieves a list of public certificates.
115 * @return a list of public certificates.
116 * @throws AppIdentityServiceFailureException
118 Collection<PublicCertificate> getPublicCertificatesForApp();
121 * Gets service account name of the app.
123 * @return service account name of the app.
125 String getServiceAccountName();
128 * Gets the default GS bucket name for the app.
130 * @return default GS bucket name for the app.
132 String getDefaultGcsBucketName();
135 * OAuth2 access token to act on behalf of the application, uncached.
137 * Most developers should use getAccessToken instead.
139 * @param scopes iterable of scopes to request.
140 * @return a GetAccessTokenResult object with the access token and expiration
141 * time.
142 * @throws AppIdentityServiceFailureException
144 GetAccessTokenResult getAccessTokenUncached(Iterable<String> scopes);
147 * OAuth2 access token to act on behalf of the application.
149 * Generates and caches an OAuth2 access token for the service account for the
150 * appengine application.
152 * Each application has an associated Google account. This function returns
153 * OAuth2 access token corresponding to the running app. Access tokens are
154 * safe to cache and reuse until their expiry time as returned. This method
155 * will do that using memcache.
157 * @param scopes iterable of scopes to request.
158 * @return a GetAccessTokenResult object with the access token and expiration
159 * time.
160 * @throws AppIdentityServiceFailureException
162 GetAccessTokenResult getAccessToken(Iterable<String> scopes);
165 * Parse a full app id into partition, domain name and display app_id.
167 * @param fullAppId The full partitioned app id.
168 * @return An {@link ParsedAppId} instance with the parsing results.
170 ParsedAppId parseFullAppId(String fullAppId);