Skip to content

BearerSecurityScheme #2181

@RRebekka

Description

@RRebekka

Hi,

I have a question regarding the Bearer Security Scheme. I have a thing that needs an Bearer token in the Authorization header for its endpoints. I want to use a Thing Description with the following security scheme:

{
  "@context": [
    "https://www.w3.org/2019/wot/td/v1",
    {
      "@language": "en"
    }
  ],
  "title": "My Protected Thing",
  "securityDefinitions": {
    "bearer_sc": {
      "scheme": "bearer",
      "in": "header",
      "name": "Authorization",
      "format": "jwt",
      "description": "JWT token obtained from authorization server"
    }
  },
  "security": ["bearer_sc"],
  "properties": {
    "status": {
      "type": "string",
      "forms": [{
        "href": "https://example/api/status",
        "op": "readproperty"
      }]
    }
  }
}

My question is know, how do I describe the process of getting this access token from the thing in a WoT-comaptible way that can be interpreted by any client. I know that there is this authorization parameter, but I cannot specify how the request and response look like, right?

I was thinking about using an action for a login endpoint like the following:

{
  "securityDefinitions": {
    "bearer_sc": {
      "scheme": "bearer",
      "in": "header",
      "name": "Authorization",
      "format": "jwt"
    },
    "nosec_sc": {
      "scheme": "nosec"
    }
  },
  "security": ["bearer_sc"],
  "actions": {
    "login": {
      "description": "Authenticate and obtain bearer token",
      "security": ["nosec_sc"],
      "input": {
        "type": "object",
        "properties": {
          "username": {"type": "string"},
          "password": {"type": "string"}
        },
        "required": ["username", "password"]
      },
      "output": {
        "type": "object",
        "properties": {
          "token": {"type": "string"}
        }
      },
      "forms": [{
        "href": "https://example/api/token",
        "htv:methodName": "POST",
        "contentType": "application/json"
      }]
    }
  }
}

However, this implies that the client needs to know, that the login endpoint has to be used before any other affordances can be used, which is implicit knowledge about the thing. Is there any other, better way for describing this use case?

Best regards,
Rebekka

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions