Service Helper

The path to success

Welcome to the Phoenix ServiceHelper. Introduction to the concept and code resource

ServiceHelper Benefits

The service helper provides a simple helper concept for consuming Phoenix abstracting away the core framework fundamentals in a simple and DRY manner whilst advocating best patterns and practices.

  1. Abstract the OAuth process and token lifecycle management
  2. Inherent version control for the API's and the code, simplifies upgrade paths
  3. Exception management and WCF best practice patterns
  4. Abstraction away from REST and SOAP strongly typed request and response objects
  5. Simple configuration and environment Management
  6. Async / Task Access Pattern support
  7. Rest URL Library and parameter definition
  8. Service Message Inspectors to extract the underlying Rest/Soap call

Configuration

The service helper behavior is configured by a simple application/web configuration entry similar to the below

Client Credentials flow is meant to give the authenticating client itself access to resources that it owns. For example, a backend system could use the credentials of the client "phoenixprocessor" to check how many users are accessing the API via this client.

<servicehelper environment="Local" requesttype="Soap" name="helper" protocol="Https">
    <authentication clientid="ClientApplication" clientsecret="ClientApplicationSecret" />
</servicehelper>

The Password flow is meant to authenticate a user to the back end system providing specific credentials for the logged in user above the resources that it owns

<servicehelper environment="Local" requesttype="Soap" name="helper" protocol="Https">
    <authentication clientid="ClientApplication" clientsecret="ClientApplicationSecret" username="jamestring" password="IAmBananaMan" />
</servicehelper>

Complete application configuration example

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <configSections>
    <section name="serviceHelper" type="Tigerspike.Phoenix.Services.Api.Configuration.ServiceHelperSection, Tigerspike.Phoenix.Services.Api, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" />
  </configSections>
  
  <serviceHelper environment="LiveSG" requestType="Soap" name="helper" protocol="Https">
    <authentication clientid="ClientApplication" clientsecret="ClientApplicationSecret" />
  </serviceHelper>
</configuration>

Getting Started

After installing the ServiceHelper and configuring your application to use the ClientCredentials or Password flow the following code can be used to Grant a Token

using System.Reflection;

using Tigerspike.Phoenix.Services.Api;
using Tigerspike.Phoenix.Services.Api.Base;
using Tigerspike.Phoenix.Services.Api.Interface;
using Tigerspike.Phoenix.Services.Api.ServiceConfiguration;

#region "Phoenix Services"
using PhoenixIdentity = Tigerspike.PhoenixIdentity.V1;
#endregion

class Program
{
    static void Main(string[] args)
    {
        // Construct a new authentication request
        var configuration = CustomConfigurationFactory.CreateServiceConfiguration();
        var authRequest = CustomConfigurationFactory.CreateClientCredential();

        var identityProxy = new PhoenixServiceHelper<PhoenixIdentity.IPhoenixIdentityService>(configuration);
        var response = identityProxy.Execute(authRequest as BaseServiceRequest, o => o.GrantToken(authRequest.GetEncodedPayload()));

        var token = response.access_token;
        var refreshToken = response.refresh_token;
    }
}