# See which agent is calling

Know the agent and its verified operator, before any person is involved.

| | |
|---|---|
| Level | 0: The agent identifies itself; no person is asked. |
| Class | `read`: Nothing changes. The approval can be reused until it ends or the person withdraws it. |

## What the test proves

- without a passport: 401 passport_required
- the app learns the agent and its verified operator; nobody is asked

## Python

```python
routes.append(route("GET", "/me", level=0, summary="Which agent is calling"))


@app.get("/me")
def me():
    return {"agent": g.allowedby.agent, "operator": g.allowedby.operator}
```

## JavaScript

```js
routes.push(route("GET", "/me", undefined, { level: 0, summary: "Which agent is calling" }));

api.get("/me", (req, res) => {
  res.json({ agent: req.allowedby.agent, operator: req.allowedby.operator });
});
```

## Go

```go
routes = append(routes, allowedby.Route{Method: "GET", Path: "/me", Level: 0, Summary: "Which agent is calling"})

mux.HandleFunc("GET /me", func(w http.ResponseWriter, r *http.Request) {
	who, _ := allowedby.ContextFrom(r.Context())
	writeJSON(w, http.StatusOK, map[string]string{"agent": who.Agent, "operator": who.Operator})
})
```

## Java

```java
@Bean
AllowedByCustomizer identify() {
    return aby -> aby.route(Route.get("/me").level(0).summary("Which agent is calling"));
}

@GetMapping("/me")
Map<String, String> me(@AllowedByContext Context ctx) {
    return Map.of("agent", ctx.getAgent(), "operator", ctx.getOperator());
}
```

## C#

```dotnet
routes.Add(Route("GET", "/me", level: 0, summary: "Which agent is calling"));

app.MapGet("/me", (AllowedByContext ctx) => new { agent = ctx.Agent, @operator = ctx.Operator });
```

## PHP

```php
$routes[] = route('GET', '/me', level: 0, summary: 'Which agent is calling');

$app->get('/me', function (Request $request, Response $response) use ($json) {
    $context = $request->getAttribute('allowedby.context');

    return $json($response, ['agent' => $context->agent, 'operator' => $context->operator]);
});
```

## Ruby

```ruby
ROUTES << AllowedBy.route("GET", "/me", level: 0, summary: "Which agent is calling")

get "/me" do
  context = env["allowedby.context"]
  { agent: context.agent, operator: context.operator }.to_json
end
```

## Rust

```rust
let aby = aby.route(Route::get("/me").level(0).summary("Which agent is calling"));
let app = app.route("/me", get(me));

async fn me(ctx: AllowedByContext) -> Json<Value> {
    Json(json!({"agent": ctx.agent, "operator": ctx.operator}))
}
```
