/pcs-auth-dotnet

Authentication micro-service for PCS

Primary LanguageC#MIT LicenseMIT

Build Issues Gitter

PCS Authentication and Authorization Overview

This service allows to manage the users authorized to access Azure IoT Solutions. Users management can be done using any identity service provider supporting OpenId Connect.

Dependencies

The service depends on:

  • Azure Active Directory used to store users and providing the certificates to validate JWT tokens signature. Any identity provider supporting OpenId Connect should work though.
  • Configuration settings to define the trusted Issuer and expected Audience.

How to use the microservice

Quickstart - Running the service with Docker

  1. Create an instance of Azure Active Directory or simply reuse the instance coming with your Azure subscription
  2. Register an application in AAD
  3. Get the Application ID and Issuer URL and store them in the service configuration.
  4. Install Docker
  5. Start the Auth service using docker compose:
    cd scripts
    cd docker
    run
    
  6. Use an HTTP client such as Postman, to exercise the RESTful API.

Running the service with Visual Studio

  1. Install any edition of Visual Studio 2017 or Visual Studio for Mac. When installing check ".NET Core" workload. If you already have Visual Studio installed, then ensure you have .NET Core Tools for Visual Studio 2017 installed (Windows only).
  2. Create an instance of Azure Active Directory or simply reuse the instance coming with your Azure subscription
  3. Get the Application ID and Issuer URL and store them in the service configuration.
  4. Open the solution in Visual Studio
  5. In Visual Studio, start the WebService project
  6. Use an HTTP client such as Postman, to exercise the RESTful API.

Project Structure

The solution contains the following projects and folders:

  • WebService: ASP.NET Web API exposing a RESTful API for Authentication functionality, e.g. show the current user profile.
  • Services: Library containing common business logic for interacting with Azure Active Directory.
  • WebService.Test: Unit tests for the ASP.NET Web API project.
  • Services.Test: Unit tests for the Services library.
  • scripts: a folder containing scripts from the command line console, to build and run the solution, and other frequent tasks.

Build and Run from the command line

The scripts folder contains scripts for many frequent tasks:

  • build: compile all the projects and run the tests.
  • compile: compile all the projects.
  • run: compile the projects and run the service. This will prompt for elevated privileges in Windows to run the web service.

Building a customized Docker image

The scripts folder includes a docker subfolder with the scripts required to package the service into a Docker image:

  • Dockerfile: Docker image specifications
  • build: build a Docker image and store the image in the local registry
  • run: run the Docker container from the image stored in the local registry
  • content: a folder with files copied into the image, including the entry point script

Configuration and Environment variables

The service configuration is stored using ASP.NET Core configuration adapters, in appsettings.ini and appsettings.ini. The INI format allows to store values in a readable format, with comments. The application also supports references to environment variables, which is used to import credentials and networking details.

The configuration files in the repository reference some environment variables that need to be created at least once. Depending on your OS and the IDE, there are several ways to manage environment variables:

Contributing to the solution

Please follow our contribution guidelines. We love PRs too.

Troubleshooting

{TODO}

Feedback

Please enter issues, bugs, or suggestions as GitHub Issues here: https://github.com/Azure/pcs-auth-dotnet/issues.