microsofthackathons / tdi

Command-line interface to Microsoft To Do
MIT License
7 stars 3 forks source link

Handle case where token has expired... #24

Open kitplummer opened 2 years ago

kitplummer commented 2 years ago
     Running `target\debug\tdi.exe me`
Error: Graph error:
GraphError {
    headers: Some(
        GraphHeaders {
            url: "https://graph.microsoft.com/v1.0/me",
            status: 401,
            header_map: {
                "transfer-encoding": "chunked",
                "content-type": "application/json",
                "strict-transport-security": "max-age=31536000",
                "request-id": "1740feb8-b33a-4c08-a6ee-ab5cfc5a18c4",
                "client-request-id": "1740feb8-b33a-4c08-a6ee-ab5cfc5a18c4",
                "x-ms-ags-diagnostic": "{\"ServerInfo\":{\"DataCenter\":\"South Central US\",\"Slice\":\"E\",\"Ring\":\"5\",\"ScaleUnit\":\"003\",\"RoleInstance\":\"SN4PEPF0000050E\"}}",
                "www-authenticate": "Bearer realm=\"\", authorization_uri=\"https://login.microsoftonline.com/common/oauth2/authorize\", client_id=\"00000003-0000-0000-c000-000000000000\"",
                "date": "Fri, 23 Sep 2022 11:57:49 GMT",
            },
        },
    ),
    code: 401,
    error_message: ErrorMessage {
        error: Some(
            ErrorStatus {
                code: Some(
                    "InvalidAuthenticationToken",
                ),
                message: Some(
                    "Access token has expired or is not yet valid.",
                ),
                inner_error: Some(
                    InnerError {
                        code: None,
                        request_id: Some(
                            "1740feb8-b33a-4c08-a6ee-ab5cfc5a18c4",
                        ),
                        date: Some(
                            "2022-09-23T11:57:50",
                        ),
                    },
                ),
            },
        ),
    },
}
kitplummer commented 2 years ago

If this happens, we should refresh the locally stored auth token with a new one, versus the whole auth life cycle, which would be a different error generated if the auth code had expired.

kitplummer commented 2 years ago

The refresh_token is not coming back with the authorization_code flow in the graph-rs lib. Need to investigate more.

kitplummer commented 2 years ago

https://github.com/sreeise/graph-rs/discussions/380 - asking the question upstream.