The paper describes a context-based access control model for a ridesharing service. Ridesharing is a shared use of a car by the driver and one or more passengers for a joint trip. The service is based on the smart space concept. For this purpose the Smart-M3 platform is used. Currently the Smart-M3 platform doesn't have an appropriate access control mechanism meeting the following requirements: supporting a flexible, descriptive and well-defined policy language and taking into consideration the context information. Therefore, the usage of the context-based access control model has been proposed. This model is built as a combination of the role-based and attribute-based access control models. It uses roles, which are assigned dynamically based on the user's context, and meets the requirements to the access control in the smart space. An analysis of information transfer through the ridesharing service modules is used for defining the user's context. The model has been implemented within an access control broker, which controls the access to the smart space resources.