Selecting a token format for your Web APIs, RESTful web services
Join the DZone community and get the full member experience.Join For Free
the most important token format that you need to support for your web apis and restful web services these days is: anything. so many platforms define their own authentication/authorization mechanism with what seems to be little concern for standardized formats: api keys here, hmac signatures there, various oauth interpretation, etc. s imple does trump standards . for the integration-focused enterprise architect, this reality creates a need for flexible infrastructure supporting arbitrary token formats.
about a year ago, i was proposing a simple approach for enabling restful web service requesters with saml-based tokens for authentication/authorization. the pattern enabling a rest client to access a service using a saml token is illustrated below.
the fact that there are still no definitive saml bindings targeting restful web services today does not seem to deter developers from leveraging saml to control access to their restful web services. we encountered this again recently in the field in the form of a proof of technology project in which the main objective was to demonstrate the layer 7 gateway acting both as the token issuer for a rest client as well as an api proxy which controls access based on those very tokens. two token formats were requested: saml and oauth.
for our gateway to authenticate restful requesters and issue tokens is a very common and straightforward process. in order for the rest client to be able to use this token however, it must be able to insert it in an authorization header (the restful location for this token). in the case where the token is a saml assertion, it can exceed in size the practical limit of what can be used as an http header value (a rich saml assertion with an xml digital signature can be quite verbose). this is where the layer 7 gateway policy language flexibility shines. by simply declaring the compression (gzip assertion) of the resulting saml before sending it back to the client, the token has now been shrunk to a manageable size for the client. the reverse decompression at reception is just as straightforward using the reverse operation in our policy language.
note that although we could just as well create a session on the gateway and return a cookie back to the requester, we are interacting with a rest client here; this is not a browser-driven interaction. besides, server side sessions are not restful. if the client re-sends the token at each call, the authorization of the requester is validated each time through the evaluation of the saml statements and this does not require any server-side session.
when implementing the same use case, but with a token format based on oauth instead of saml, this compression/decompression step is no longer needed. the rest of the configuration using our gateway policy language is very similar. this compression is one of the technical tradeoffs when choosing between such token formats and relates to the so-called “open” vs “enterprise” identity camps. on one hand, you have a rich and standardized token format (saml), which can be used to express a variety of statements about an identity. on the other hand you have a simple and lean token format but less standardized. on that last point, what constitutes an oauth token format in this particular context is a bit of a moving target and various interpretations are not necessarily compatible.
in the end, choosing a token format should consider the requirements around authorization and the technical capabilites of the parties involved. better yet, don’t narrow your support on a single format. support and enable different token formats instead if that is what is needed.
when selecting supporting infrastructure to manage apis and broker with cloud or partners , keep in mind this need to accommodate arbitrary authentication approaches. although rich standard support provides value, the essential ingredient of an agile service gateway is its flexibility and its extensibility.
Published at DZone with permission of Francois Lascelles, DZone MVB. See the original article here.
Opinions expressed by DZone contributors are their own.