Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Detecting if a front end token is available to execute

How can I detect if a front end token is available to execute? Alternately, how can I detect if a front end token failed to execute?

Example: the Edit -> Copy command is not available if nothing is selected. FrontEndTokenExecute["Copy"] will simply beep in this case, but it gives me no (programmatic) indication that it has failed.

like image 768
Szabolcs Avatar asked Jan 01 '12 18:01

Szabolcs


People also ask

Is there any way to check if OAuth token is expired or not?

The easiest way is to just try to call the service with it. It will reject it if it is expired and then you can request a new one. You can also keep the time you received the token and use the expires_in to calculate when it will approximately expire.

How do you check if a JWT token is valid or not?

To verify JWT claimsVerify that the token is not expired. The aud claim in an ID token and the client_id claim in an access token should match the app client ID that was created in the Amazon Cognito user pool. The issuer ( iss ) claim should match your user pool.


1 Answers

I found a method to deal with your second question, but it's not elegant:

  1. In Preferences > Interface > Message and Warning actions set Minor user interface warnings to Beep and Print to Console
  2. Make sure there is at least one error message in the message window
  3. Obtain a handle to the message window notebook (using Notebooks[] or so)
  4. Store the last cell in the message notebook using NotebookGet[NotebookObject[FrontEndObject[LinkObject["55d_shm", 1, 1]], 1]]/. Notebook[{___, Cell[a___]}, ___] :> Cell[a] (your handle will look differently, of course)
  5. Your call: FrontEndTokenExecute["Copy"]
  6. Get the last error message and check whether it differs from the one stored in step 4.
  7. The error cell looks like Cell["You tried to edit a cell that is not editable. You can make the \ cell editable by choosing Cell Editable in the Cell Properties \ submenu.", "Message", "Message", "MSG", PageWidth -> WindowWidth, ShowCellLabel -> True, CellChangeTimes -> {3.534442831*10^9}, CellTags -> "cantEditLockedCell"]
  8. Act appropriately
like image 71
Sjoerd C. de Vries Avatar answered Sep 30 '22 12:09

Sjoerd C. de Vries