Count OAuth2 access token

Hi

I'm administrator of APIGee Edge (On-Premises) and I want to know if there is a way to count oauth2 access token ?

Thanks

Maxime

2 8 502
8 REPLIES 8

Dear @msavary , Welcome to Apigee community 🙂

Do you mean how many access tokens has been issued / expired / active for entire org / app / developer ?

Yes, that's it

Maxime

vijay
New Member

Maxime,

No, there is no way to get the count of access-tokens. There are no apis to get the count of access-tokens.

Thanks and Regards,

Vijayakumar.

@msavary

You cannot get the count of all outstanding tokens by organization or environment. You cannot get the count of expired tokens in any case. You CAN get the count of outstanding tokens by developer app. Eg

curl -i -n \
https://api.enterprise.apigee.com/v1/o/ORGNAME/developers/example@example.com/apps/MyAppName/oauth2a...

This returns something like:

{
  "value" : 12
}

@Dino That api is unreliable. It would only return a max of 10000 since that's the default limit of rows that can be fetched from Cassandra. So we are planning to deprecate this API since it doesn't give accurate results.

We have already deprecated the api which returned access tokens for the entire org:

curl -i -n \
https://api.enterprise.apigee.com/v1/o/ORGNAME/oauth2/accesstokens


{
  "code" : "keymanagement.service.FetchCountOperationNotSupported",
  "message" : "keymanagement.service.FetchCountOperationNotSupported",
  "contexts" : [ ]
}

Former Community Member
Not applicable

@msavary I am curious about the requirement to be able to count the number of access tokens. Is this for reporting? For something else?

The goal is to monitor the number of tokens in the DB. Another question : does Apigee automatically delete the expired tokens ?

Not applicable

msavary, try getting the data from C* directly.

You can use select count(*) from kms.oauth_20_access_tokens but as @arghya das mentioned the default limit is 10,000.

If you think you have more than 10,000 you can try some thing like this

select count(*) from kms.oauth_20_access_tokens limit 1000000; but you may see some timeouts I guess? just give it a try.

or you can also get an estimate using nodetool cfstats which will give you some thing like below

Column Family: oauth_20_access_tokens 
SSTable count: 0 
Space used (live): 0 
Space used (total): 0 
SSTable Compression Ratio: 0.0 
Number of Keys (estimate): 0 
Memtable Columns Count: 0

Pls refer this link http://docs.apigee.com/api-services/content/oauthv2-policy#purgingaccesstokens for your second question.