【问题标题】:GAE Cloud Endpoint not showing 401 auth errorGAE Cloud Endpoint 未显示 401 身份验证错误
【发布时间】:2015-02-08 06:21:45
【问题描述】:

我正在尝试使用身份验证来保存配置文件,但即使用户为空,GAE 端点也不会给出 401 错误。

相反,Endpoint 以 200 ok 响应并给出默认结果。

顺便说一句,这是Udacity Course 的一部分。

/**
 * Creates or updates a Profile object associated with the given user
 * object.
 *
 * @param user
 *            A User object injected by the cloud endpoints.
 * @param profileForm
 *            A ProfileForm object sent from the client form.
 * @return Profile object just created.
 * @throws UnauthorizedException
 *             when the User object is null.
 */

// Declare this method as a method available externally through Endpoints
@ApiMethod(name = "saveProfile", path = "profile", httpMethod = HttpMethod.POST)
// The request that invokes this method should provide data that
// conforms to the fields defined in ProfileForm

// TODO 1 Pass the ProfileForm parameter
// TODO 2 Pass the User parameter
public Profile saveProfile(final User user) throws UnauthorizedException {

    String userId = null;
    String mainEmail = null;
    String displayName = "Your name will go here";
    TeeShirtSize teeShirtSize = TeeShirtSize.NOT_SPECIFIED;

    // TODO 2
    // If the user is not logged in, throw an UnauthorizedException
    if(user== null){
        throw new UnauthorizedException("Authorization Required!");
    }
    // TODO 1
    // Set the teeShirtSize to the value sent by the ProfileForm, if sent
    // otherwise leave it as the default value

    // TODO 1
    // Set the displayName to the value sent by the ProfileForm, if sent
    // otherwise set it to null

    // TODO 2
    // Get the userId and mainEmail

    // TODO 2
    // If the displayName is null, set it to default value based on the user's email
    // by calling extractDefaultDisplayNameFromEmail(...)

    // Create a new Profile entity from the
    // userId, displayName, mainEmail and teeShirtSize
    Profile profile = new Profile(userId, displayName, mainEmail, teeShirtSize);

    // TODO 3 (In Lesson 3)
    // Save the Profile entity in the datastore

    // Return the profile
    return profile;
}

【问题讨论】:

    标签: google-app-engine google-cloud-endpoints


    【解决方案1】:

    不幸的是,它是known issue。转到"Star" this issue 以获取有关何时修复的更新。第一个链接中有几个解决方法,这里引用它:

    有两种解决方法 (1) 保存用户并从 商店,如果它指的是一个有效的帐户,用户 ID 将被填充 (这很糟糕,因为您支付了保存/加载/删除成本 每个经过身份验证的 API 访问,即使它很小,并且 显然有一些性能成本)和(2)你可以使用 google+ ID 但这与用户 ID 不同。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2022-01-06
      • 2012-07-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-03-13
      • 2011-11-05
      • 1970-01-01
      相关资源
      最近更新 更多