> ## Documentation Index
> Fetch the complete documentation index at: https://docs.apowerb.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Microsoft Service Callback

> Complete the Microsoft OAuth flow for a specific service.

The frontend calls this after Microsoft redirects back to the callback page
with a temporary ``code``. This endpoint:
  1. Validates the service key
  2. Validates the CSRF ``state`` against the server-side store
  3. Exchanges the code for an access + refresh token (service-specific scopes)
  4. Fetches the Microsoft Graph user profile
  5. Upserts the integration row under provider='microsoft_{service}'
  6. Returns basic integration info (never the raw token)



## OpenAPI

````yaml /api-reference/openapi.json post /api/integrations/microsoft/{service}/callback
openapi: 3.1.0
info:
  title: apowerb API
  description: REST API of the apowerb agentic framework (open-source edition).
  version: 0.1.2
  license:
    name: MIT
    url: https://github.com/apowerb/apowerb/blob/main/LICENSE
servers:
  - url: https://api.example.com
    description: Your apowerb instance
  - url: http://localhost:8000
    description: Local stack
security: []
paths:
  /api/integrations/microsoft/{service}/callback:
    post:
      tags:
        - integrations
      summary: Microsoft Service Callback
      description: >-
        Complete the Microsoft OAuth flow for a specific service.


        The frontend calls this after Microsoft redirects back to the callback
        page

        with a temporary ``code``. This endpoint:
          1. Validates the service key
          2. Validates the CSRF ``state`` against the server-side store
          3. Exchanges the code for an access + refresh token (service-specific scopes)
          4. Fetches the Microsoft Graph user profile
          5. Upserts the integration row under provider='microsoft_{service}'
          6. Returns basic integration info (never the raw token)
      operationId: >-
        microsoft_service_callback_api_integrations_microsoft__service__callback_post
      parameters:
        - name: service
          in: path
          required: true
          schema:
            type: string
            title: Service
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/MicrosoftCallbackRequest'
      responses:
        '200':
          description: Successful Response
          content:
            application/json:
              schema: {}
        '422':
          description: Validation Error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/HTTPValidationError'
      security:
        - HTTPBearer: []
components:
  schemas:
    MicrosoftCallbackRequest:
      properties:
        code:
          type: string
          title: Code
        state:
          type: string
          title: State
        service:
          type: string
          title: Service
          default: outlook
        redirect_uri:
          anyOf:
            - type: string
            - type: 'null'
          title: Redirect Uri
      type: object
      required:
        - code
        - state
      title: MicrosoftCallbackRequest
      description: Payload the frontend POSTs after Microsoft redirects back.
    HTTPValidationError:
      properties:
        detail:
          items:
            $ref: '#/components/schemas/ValidationError'
          type: array
          title: Detail
      type: object
      title: HTTPValidationError
    ValidationError:
      properties:
        loc:
          items:
            anyOf:
              - type: string
              - type: integer
          type: array
          title: Location
        msg:
          type: string
          title: Message
        type:
          type: string
          title: Error Type
        input:
          title: Input
        ctx:
          type: object
          title: Context
      type: object
      required:
        - loc
        - msg
        - type
      title: ValidationError
  securitySchemes:
    HTTPBearer:
      type: http
      scheme: bearer

````

## Related topics

- [Microsoft Service Connect](/api-reference/integrations/microsoft-service-connect.md)
- [Integrations](/guides/integrations.md)
- [Google Callback](/api-reference/integrations/google-callback.md)
- [Oauth Callback](/api-reference/emailing/oauth-callback.md)
- [Github Callback](/api-reference/integrations/github-callback.md)
