Skip to content

[Question] Is it possible to add CORS configuration for authorized failed response? #3

@hhashoww

Description

@hhashoww

Hello,

I'm trying to implement the authorization logic in my project,
I face a CORS problem when I get the Unauthorized (401) response from the oatpp server

image

I know there is a macro ADD_CORS that can handle the CORS problem at each END POINT
but Is it possible to add CORS configuration in my authorize callback function?

class BearerAuthorizationObject : public oatpp::web::server::handler::AuthorizationObject {
 public:
  // oatpp::String user;
  // oatpp::String password;
  oatpp::String token;
};

class MyBearerAuthorizationHandler : public oatpp::web::server::handler::BearerAuthorizationHandler {
 public:
  MyBearerAuthorizationHandler() : oatpp::web::server::handler::BearerAuthorizationHandler("my-realm") {}

  std::shared_ptr<AuthorizationObject> authorize(const oatpp::String& token) override {

    if (token == "4e99e8c12de7e01535248d2bac85e732") {
      auto obj = std::make_shared<BearerAuthorizationObject>();
      obj->user = "foo";
      obj->password = "bar";
      obj->token = token;
      return obj;
    }

    return nullptr;
  }
};

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions