Basic Auth headers with Citizen Space

What is Basic Authentication?

Basic Authentication is a common approach for authenticating to an API. Often it's the case where it's the base64 encoding of username and a password separated by a colon like so username:password.

Authenticating to an API in Citizen Space requires a request header is sent in the following format:

  • Key = 'Authorization'

  • Value = 'Basic' + base 64 encoding of a key and secret combined with a colon

Citizen Space makes it particularly easy to generate, manage, and use keys and you can see where you would collect this information from in the image below.

A visual showing where the 'Key' and 'Secret' can be found on the Citizen Space dashboard

Practical example

In this example we want to replicate a scenario in which a person in an organisation has asked to pull the latest site wide activity data from our Citizen Space into a third party analysis tool.

We can do that simply by amending the site URL:

List activities

GET /api/1/activities

Return a filtered list of all activities.

https://demo.citizenspace.com/api/1/activities

Without proper authentication this will return an error:

Citizen Space error message

Successful Request

By encoding our key and secret and using Basic Authentication we can return the following:

List activities

GET /api/1/activities

Return a filtered list of all activities.

https://demo.citizenspace.com/api/1/activities

Headers

Key
Value

Authorization

Basic MjcxMzI3RENGQzVCNEU3NEE0MDI0NDkxMDM4QS4uLi46dkVta3NLQThSSEFYWXM2V01rWFpydmJ4UUthNjJyMnV6Q3h3ZndoWktXNmZ5Z0JDTWJZeHpEdlRVNy4uLi4=

Response

[
    {
        "uid": "67f18beb302944c9944e06521cf2224e",
        "title": "Smallville resident forum",
        "state": "open",
        "start_date": "2023-03-29T00:00:00",
        "end_date": "2027-03-26T00:00:00",
        "path": "demo/smallville-resident-forum"
    },
    {
        "uid": "ce620a61c70647ea90c8c63e6faefb3f",
        "title": "Mediumville resident forum",
        "state": "open",
        "start_date": "2023-03-29T00:00:00",
        "end_date": "2027-03-26T00:00:00",
        "path": "demo/mediumville-resident-forum"
    },
    {
        "uid": "4c55f1f0f9c34c248fbd6094770fe833",
        "title": "Take part in the latest panel survey",
        "state": "open",
        "start_date": "2023-03-29T00:00:00",
        "end_date": "2027-03-25T00:00:00",
        "path": "demo/take-part-in-the-latest-panel-survey"
    },
]    

Last updated