andstatus / andstatus

Multiple accounts client for multiple Social networks. For Android
http://andstatus.org/
Apache License 2.0
309 stars 71 forks source link

"Reverify credentials" doesn't detect access problem #574

Closed yvolk closed 1 year ago

yvolk commented 1 year ago

On the Account settings screen AndStatus has "Reverify Credentials" button that is meant to check if stored credentials (access token for OAuth) are still valid. This works for Twitter (?), GnuSocial and Mastodon APIs that have dedicated protected "verify_credentials" endpoints, Pump.io does have "whoami" endpoint also. For ActivityPub AndStatus uses "me" URL as defined in IndieAuth https://indieauth.spec.indieweb.org/#access-token-verification-response But the problem is that the endpoint is not protected, and it can be accessed even without authorization. (@tsileo noticed this in https://github.com/andstatus/andstatus/issues/561#issuecomment-1356817535)

This means that "me" URL cannot be used for access verification. In terms of OAuth this could be "Token Introspection" as defined in https://www.rfc-editor.org/rfc/rfc7662 Unfortunately, no concrete URL of the endpoint is defined in the spec.

tsileo commented 1 year ago

Maybe the OAuth 2.0 Authorization Server Metadata (https://www.rfc-editor.org/rfc/rfc8414.html) can be used here too? introspection_endpoint is defined there.

I can add it in microblog.pub if you think that's useful?

Thanks!

yvolk commented 1 year ago

Yes, I think this will be the most "standard" way :-) "introspection_endpoint" is enough.

tsileo commented 1 year ago

I just added it and redeployed your test instance.

It is advertised in the OAuth metadata and requires both:

Here is an example of a successful response:

{                                                                                                             
    "active": true,                                                                                           
    "client_id": "https://micropublish.net/",                                                                 
    "exp": 1675280767,                                                                                        
    "scope": "create update delete undelete"                                                                  
}                                                                                                             

Let me know if that works, thank you!

yvolk commented 1 year ago

@tsileo I'm trying this and getting "401 Unauthorized" although I'm posting the same way as for access token request, i.e. with "Client Authentication".

        val request = OAuthRequest(api.accessTokenVerb, introspectionEndpoint)
        api.clientAuthentication.addClientAuthentication(request, apiKey, apiSecret)
        request.addParameter("token", accessToken);
        request.addParameter("token_type_hint", "access_token")

See also https://github.com/scribejava/scribejava/issues/898#issuecomment-720194204

tsileo commented 1 year ago

Good catch, sorry about that. I just pushed and redeployed a fix. Thanks!

yvolk commented 1 year ago

It works, thank you!