我正尝试从GAE中的Channel API迁移到Firebase。要做到这一点,首先,我试图建立一个本地开发环境。我从GAE样本中克隆了示例应用程序。 (Link to sample)从频道api迁移到firebase
当我运行这个时,当Web客户端尝试使用Firebase DB进行身份验证时,出现以下错误。错误在控制台中。
即令牌认证failed.Clearly,这点到生成JWT是不正确的事实。
可以肯定的,我也做了以下内容:
- 创建于谷歌的云主机服务帐户。
- 下载的JSON,并指出这JSON在环境变量“GOOGLE_APPLICATION_CREDENTIALS”
- 将/从火力剪断成WEB-INF /视图的代码firebase_config.jspf文件
生成令牌的代码是作为(来自FirebaseChannel.java)如下
public String createFirebaseToken(Game game, String userId) { final AppIdentityService appIdentity = AppIdentityServiceFactory.getAppIdentityService(); final BaseEncoding base64 = BaseEncoding.base64(); String header = base64.encode("{\"typ\":\"JWT\",\"alg\":\"RS256\"}".getBytes()); // Construct the claim String channelKey = game.getChannelKey(userId); String clientEmail = appIdentity.getServiceAccountName(); System.out.println(clientEmail); long epochTime = System.currentTimeMillis()/1000; long expire = epochTime + 60 * 60; // an hour from now Map<String, Object> claims = new HashMap<String, Object>(); claims.put("iss", clientEmail); claims.put("sub", clientEmail); claims.put("aud", IDENTITY_ENDPOINT); claims.put("uid", channelKey); claims.put("iat", epochTime); claims.put("exp", expire); System.out.println(claims); String payload = base64.encode(new Gson().toJson(claims).getBytes()); String toSign = String.format("%s.%s", header, payload); AppIdentityService.SigningResult result = appIdentity.signForApp(toSign.getBytes()); return String.format("%s.%s", toSign, base64.encode(result.getSignature())); }
代替步骤#2,也已经尝试“gcloud AUTH应用缺省登录”,然后取消设置的环境变量之后运行 - 导致SAM e问题
感谢此方面的任何帮助。