Introduction Last updated: 27-05-2024
Welcome to sCloud's API Documentation.
We have made our API simple to understand and have also provided usage examples in various programming languages to help developers explore them.
sCloud API uses the {JSON} Protocol that returns JSON-encoded responses and uses standard HTTP response codes, authentication.
Adaptive API Versioning, our (Basenames) and (Endpoints) stay static regardless of the API Version,
this saves time by not keep updating your implementation with newer api versions.
This first section describes connecting to the API with endpoints and then also how to connect using the SDK and also non SDK examples.
If you prefer to not use the endpoints directly you can jump straight in using a ready made Library/SDK.
A SDK is a software development kit, although comes in verious coding languages it's basically a wrapper around the sCloud's API endpoints,
this allows developers to create applications quicker and with more ease than using the endpoints directly.
Developers are welcome to indulge in our SDK's,
infact we encourage you to explore and help us build our SDK's, they are open source and publicly available on github.
You need to register your app in the developers console before you can use the API.
Getting started
First thing you will need to do before you can use the sCloud API is to create an application.
1. User authentication and authorizing your app
sCloud uses OAuth 2.0 for API authentication, authorization and to generate access tokens.
Authorization flow
web flow
code flow
Application Registration
Register your app in the developers dashboard as shown in the figures below.
You will need an sCloud account, if you don't already have an account you can create one here
Application creation screen:
Below is a screenshot of the app creator screen on the developers dashboard website. Developers dashboard.
Required information needed on the application creation screen:
Application name | This is the name of your application that will connect to sCloud's API. |
---|---|
OAuth redirect URI | Your application return url must match this, otherwise an error will be thrown, refer to our error list for more information on errors. |
Website | Your application website describing your app. |
Optional Image | Add a image that is shown when people connect or authorize your app. This can optionally be retrieved from your sCloud photo storage account. |
Finally a short description about your app. | Input a short description about your app. |
You can also delete your application from the developers dashboard you can also view, revoke and change your access tokens for your appplication aswell as revoke individual authorized users of your registered application.
OAuth 2.0 Authorization
Once you have created your application information in the developers dashboard you can
then authorize users on to your registered app via the OAuth 2.0 authorization protocol .
First step in authorizing your application is to generate a authorization link to sCloud
that allows your user to approve/authorize or deny your application:
GET https://scloud.live/OAuth2/authorize?client_id={app_key}&scope={scope}
&response_type=code&redirect_uri={redirect_uri}&state={state}
view raw
client_id | The app's key, found in the Developers dashboard.. |
---|---|
OAuth redirect URI | Where to redirect the user after authorization has completed. This must be the exact URI registered in the Developers Dashboard. |
response_type | The grant type requested, either token or code. |
scope | This parameter allows your user to authorize a subset of the scopes selected in the Developers dashboard. Multiple scopes are separated by a space. If this parameter is omitted, our authorization page will request all scopes selected on the Permissions tab. Read about scopes in the OAuth Guide. |
state | The state parameter serves two functions. When the user is redirected back to your app, whatever value you include as the state will also be included in the redirect. This gives your app a chance to persist data between the user being directed to sCloud's authorization server and back again, such as using the state parameter as a session key. This may be used to indicate what action in the app to perform after authorization is complete, for example, indicating which of your app’s pages to redirect to after authorization. The state parameter also serves as a CSRF protection mechanism if it contains a random value per request. When the user is redirected back to your app, double check that the state value matches what you set it to originally. See Sections 4.4.1.8 and 4.4.2.5 of the OAuth 2.0 threat model spec. |
1. Example using our SDK
Generates a authorization url to sCloud authorization server.$sCloud->generateAuthUrl(1);
view raw
sCloud redirects the user back to the app, sCloud's API will return a (code) response in the return URL. The redirect will include a code in the URL and the original state parameter that you provided on the authorization request..
https://example-app.com/?code=zxaskrDczMzRlNDEwY&state=9dda75bd30
OAuth 2.0 Access Token
Your application will need to receive an access token before it can make API calls this is done via the OAuth 2.0 protocol using the returned code response from the authorizaton request this is then exchanged for a access token.
curl https://scloud.live/OAuth2/access_token \
-d code=AUTHORIZATION_CODE \
-d grant_type=authorization_code \
-d redirect_uri=REDIRECT_URI \
-d client_id=APP_KEY \
-d client_secret=APP_SECRET
//CURL headers
POST /OAuth/token HTTP/1.1
Host: https://scloud.live/OAuth2/access_token
code=Yzk5ZDczMzRlNDEwY
&grant_type=code
&redirect_uri=https://example-app.com/cb
&client_id=mRkZGFjM
&client_secret=ZGVmMjMz
&code_verifier=Th7UHJdLswIYQxwSg29DbK1a_d9o41uNMTRmuH0PM8zyoMAQ
view raw
// Exchange the auth code for an access token
$token = API('token', array(
'grant_type' => 'authorization_code',
'client_id' => $SkycloudClientID,
'client_secret' => $SkycloudClientSecret,
'redirect_uri' => $baseURL,
'code' => $_GET['code']
));
view raw
client_id | (String) The app's key, found in the Developers dashboard.. |
---|---|
OAuth redirect URI | (String) Where to redirect the user after authorization has completed. This must be the exact URI registered in the Developers Dashboard. |
grant type | authorization_code |
code | The code that was returned in the redirect after a user authorized your application. |
client_secret | Secret key known only to the application. It is essentially the application’s own password. |
You should store the returned values from the response in a database of your choice so you can use it anytime you need to and associate it with the user it belongs to and use the access_token from now on instead of sending the user through the authorization flow on each API authorization flow. Use the refresh_token returned to automatically renew the expired token via the refresh token flow.
Application authorized users. 1.5
Your app retrieves a access token for each authorized user of your application, the access token is the key to connect to the authorized users sCloud account. Each user authorized can instantly revoke access to your application from with in (My sCloud Dashboard) if desired.
API Requests
All API requests need a access token to be able to use the functionality of the API.