Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Access to any NBIA Search with Authentication REST API  API requires an authentication access token.  

A request for a an access token takes the following structure. Note that USERNAME should be your TCIA username and PASSWORD should be your TCIA password.

Code Block
titleStructure of a Request for a Token
curl -X -v -d "username=USERNAME&password=PASSWORD&client_id=NBIA&grant_type=password" -X POST -k https://services.cancerimagingarchive.net/nbia-api/oauth/token

...

  1. The application requests credentials. The credentials you pass are different depending on if you want to access public or restricted data (see above).
  2. The application sends a request to the service using the credentials you provided as a query string for the body. 

    • grant_type=password
    • username=your TCIA username
    • password=your TCIA password
  3. The service responds with access token details and expiration information.

    • access_token
    • expires_in
    • refresh_expires_in
    • refresh_token
    • not-before-policy
    • session_state_type

    The application makes a request for resources using the returned access token. All APIs listed for accessing public data also support secure access to restricted data with an additional parameter for the access token. 

...

A successful token request returns a standard access token in JSON format. The value after "access_token" will likely be longer than this example.

Code Block
titleSample Token Return Value
{"access_token":"f7889076-b3e4-4768-9419-3cd973adda76","token_type":"bearer","refresh_token":"671bb72b-f929-4ef5-a4d7-b52341a6007a","expires_in":7199}

...

Code Block
titleSample NBIA Search with Authentication REST API Call
# Request for modality values

curl -H "Authorization:Bearer YOUR_ACCESS_TOKEN" -k "https://services.cancerimagingarchive.net/nbia-api/services/v2/getModalityValuesAndCounts?Collection=LIDC-IDRI"

...

The time it takes tokens to expire is configurable but is currently two hours.
You can refresh your access token for an additional two hours by passing the refresh token from your original token request.

Code Block
titleSample Request for Refreshing the
Code Block
titleSample Request for Refreshing the Token
# Request for refreshing the token  

$ curl -X -v -d  "refresh_token=YOUR_TOKENusername=USERNAME&client_id=nbiaRestAPIClient&client_secret=ItsBetweenUAndMe&nbia&grant_type=refresh_token&refresh_token=YOUR_REFRESH_TOKEN" -X POST -k https://servicesnbia.cancerimagingarchive.net/nbia-api/oauth/token
        
/nbia-api/oauth/token"

In the following result, 119 is 7200 is the seconds before the token expires.

Code Block
titleSample Return ValueReturn Value
{"access_token":"YOUR_ACCESS_TOKEN","expires_in":7200,"refresh_expires_in":7200,"refresh_token":"YOUR_REFRESH_TOKEN","token_type":"Bearer","id{"access_token":"YOUR_ACCESSID_TOKEN","token_typenot-before-policy":"bearer"0,"refreshsession_tokenstate":"671bb72b531425b6-f929425d-4ef544f8-a4d7bc74-b52341a6007a41200d6803c0","expires_inscope":119"openid profile email"}

Logging Out

The following is an example request to log out.

Code Block
titleSample Request to Log OutLogout
# Request for logout     
      
curl -X -v 
$ curl -Hd "Authorization:Bearer YOUR_ACCESS_TOKEN" -k "https://services.cancerimagingarchive.net/nbia-api/logout"

...