如何在devserver上使用Oauth测试云端点 [英] How do I test Cloud Endpoints with Oauth on devserver

查看:96
本文介绍了如何在devserver上使用Oauth测试云端点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用使用Oauthed云端点,并且在生产中工作正常。



我的问题是,在本地devserver上,我的用户用户始终设置为 example@example.com ,即使我已经离开通过通常的身份验证,访问代码等等等等,并有一个有效的authed用户。



我得到那个example@example.com是有用的,在我有之前测试oauth端点oauth正常工作,但由于我的应用程序正在工作,我宁愿看到那里的实际用户。

具体而言,我的端点方法是

  @ApiMethod( name =insertEmp)等
public Emp insertEmp(User user,Emp emp){
System.out.println(user.getEmail()); //(A)logappengineemail
System.out.println(OAuthServiceFactory.getOAuthService()。getCurrentUser()。getEmail(); //(B)记录认证电子邮件

...

部署时,一切正常,并且(A)和(B) (b)在本地devserver上测试时,(A)总是记录example@example.com,即使我已经通过了Oauth序列,并且拥有一个有效的,已通过身份验证的用户,并且(B)记录了my.email@gmail.com,因此我可以进行高保真度测试,我需要用户成为真正的身份验证用户。 >

所以简单来说,我如何得到(A)和(B)是相同的?

看来这是无法完成的,我通过将下面的代码放在我的Endpoint方法的顶部来结束编码。 b
$ b

  if(example@example.com.equalsIgnoreCase(user.getEmail()){
user = new User(O 。AuthServiceFactory.getOAuthService()getCurrentUser()getEmail(), foo 的)。





现在,即使在devserver上,用户电子邮件也与Oauth电子邮件相匹配。 / p>

My app uses Oauthed Cloud Endpoints and is working fine in production.

My problem is that on the local devserver, my User user is always set to example@example.com, even though I've gone through the usual auth, access code, etc etc etc and have a valid authed user.

I get that example@example.com is useful to test oauth endpoints before I have oauth working properly, but since my app is working I'd rather see the actual user there.

To be specific, my endpoint method is

@ApiMethod(name = "insertEmp"), etc
public Emp insertEmp(User user, Emp emp) {
      System.out.println(user.getEmail());  // (A) log "appengine" email
      System.out.println(OAuthServiceFactory.getOAuthService().getCurrentUser().getEmail(); // (B) log authed email

       ...

When deployed, everything is fine, and both (A) and (B) log the authenticated user (my.email@gmail.com).

When testing on my local devserver, (A) always logs "example@example.com", even though I have gone through the Oauth sequence and have a valid, authenticated user, and (B) logs my.email@gmail.com. So I can do hi-fidelity testing, I need the User to be the real authenticated user.

So in simple terms, how do I get (A) and (B) to be the same?

解决方案

It seems it can't be done. I've ended up coding around it by putting the following code at the top of my Endpoint methods.

if ("example@example.com".equalsIgnoreCase(user.getEmail()) {
    user = new User(OAuthServiceFactory.getOAuthService().getCurrentUser().getEmail(),"foo");
}

So now, even on devserver, the User email matches the Oauth email.

这篇关于如何在devserver上使用Oauth测试云端点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆