Example #1
0
        /// <summary>
        /// This sample illustartes a simplified token exhange flow.
        /// The configurations neccessary in HelseID are:
        ///
        /// The subject-client which is an ordinary client
        /// The client is configured with:
        ///     - grant_type: authorization_code
        ///     - secret: some enterprise sertificate
        ///     - scopes: an api-scope which belongs to the api doing token exchange
        ///
        /// The api-resource being called by the subject-client.
        /// The resource is configured with:
        ///     - scopes: the api scope used by the subject client.
        ///     - user claims: pid, security_level
        ///
        ///
        /// The actor-client. This is the client doing token exchange on behalf of the api-resource.
        /// The client is configured with:
        ///     - grant_type: token_exchange
        ///     - secret: some enterprise certificate
        ///     - scopes: the scopes of other API-s the api-resource needs access to
        ///
        ///
        /// NOTE: For convenience we are using the same enterprise certificate for the subject and actor client.
        ///       In normal use cases this would be two different certificates.
        ///
        /// </summary>
        /// <returns></returns>
        public static async Task MainAsync()
        {
            var settings             = GetSettings();
            var signinService        = new SignInService(settings);
            var tokenExchangeService = new TokenExchangeService(settings);

            Console.WriteLine("+---------------------------------------+");
            Console.WriteLine("|      Token Exchange Demo Client       |");
            Console.WriteLine("+---------------------------------------+");
            Console.WriteLine("");

            Console.WriteLine("Logging in and retrieving subject access token...");


            // Authenticate user, using an enterprise certifikate as client secret
            var subjectToken = await signinService.SignIn();

            Console.WriteLine("Exchanging token...");

            // In a real-world scenarion we would pass the subject token (which
            // is an access token) on to an API, and that API would do the Token Exchange.
            // Here we do the exchange on the fly.
            var teToken = await tokenExchangeService.Exchange(subjectToken);

            Console.WriteLine("Token exchange complete.");
            PrintTokens(subjectToken, teToken);

            Console.WriteLine("Press any key...");
            Console.ReadKey();
        }
 public BasketsController(IBasketRepository basketRepository,
                          IMapper mapper,
                          IMessageBus messageBus,
                          IDiscountService discountService,
                          TokenExchangeService tokenExchangeService)
 {
     this.basketRepository     = basketRepository;
     this.mapper               = mapper;
     this.messageBus           = messageBus;
     this.discountService      = discountService;
     this.tokenExchangeService = tokenExchangeService;
 }
Example #3
0
 public BasketController(
     ILogger <BasketController> logger,
     IBasketRepository repository,
     IPublishEndpoint publishEndpoint, IMapper mapper, TokenExchangeService tokenExchangeService, IConfiguration config, HttpClient client)
 {
     _logger               = logger;
     _repository           = repository;
     _publishEndpoint      = publishEndpoint;
     _mapper               = mapper;
     _tokenExchangeService = tokenExchangeService;
     _config               = config;
     _client               = client;
 }