Skip to end of metadata
Go to start of metadata

See how the leave request scenario can be realized in an Android App leveraging SAP NetWeaver Gateway and the OAuth 2.0 SAML Bearer Assertion Flow. 

Table of Contents:

The Scenario

Configuration Guide for this scenario

To get this scenario running several configuration steps have been performed. Click on the links below to see the step-by-step descriptions for the various components involved.

Configuration Step

Tools used

OData Service Enablement
OAuth 2.0 enabling of the approval service, OAuth 2.0 Scope creation and assignment

SAP NetWeaver Gateway Transaction /IWFND/MAINT_SERVICE

Trust Relationship to the Security Token Service (STS)
Configure the Gateway System to trust SAML Bearer assertions issued by the STS

Transaction SAML2

Security Token Service Setup
Registration of the SAP NW Gateway System in order for the STS to be able to issue SAML Assertions for it

Security Token Service Configuration

OAuth 2.0 Client Registration
Registration of the OAuth 2.0 client “LEAVEAPP”, which is the client the Android App is using to make calls on behalf of the resource owner user

Transaction SOAUTH2

Resource Owner Authorizations
Assignment of authority object S_SCOPE next to the manager and employee users' usual permissions

Transaction PFCG

Message Flows

See the http messages the App exchanges with the Security Token Service and the SAP NetWeaver Gateway system.

1. Security Token Request

After the logon button is pressed the app will attempt to get a SAML Assertion from the Security Token Service. For this sake it’s using the WS-Trust protocol.

Content-Type: application/soap+xml; charset=utf-8
Content-Length: 1953
Expect: 100-continue
Accept-Encoding: gzip, deflate
Connection: Keep-Alive

<s:Envelope xmlns:s="" xmlns:a="" xmlns:u="">
		<a:Action s:mustUnderstand="1"></a:Action>
		<a:To s:mustUnderstand="1"></a:To>
		<o:Security s:mustUnderstand="1" xmlns:o="">
			<u:Timestamp u:Id="_0">
			<o:UsernameToken u:Id="uuid-322dfa37-981c-4642-8b1a-2dd1e02d26b7-1">
				<o:Password Type="">Boss123</o:Password>
		<trust:RequestSecurityToken xmlns:trust="">
			<wsp:AppliesTo xmlns:wsp="">
			<i:RequestDisplayToken xmlns:i=""/>

2. Security Token Response

After a successful authentication at the Security Token Service a SAML assertion will be sent back inside a WS-Trust Security Token Response.

HTTP/1.1 200 OK
Date: Thu, 14 Mar 2013 08:15:39 GMT
Content-Length: 5987
Content-Type: application/soap+xml; charset=utf-8
Keep-Alive: timeout=5, max=100
Connection: Keep-Alive

<s:Envelope xmlns:s="" xmlns:a="" xmlns:u="">
		<a:Action s:mustUnderstand="1"></a:Action>
		<o:Security s:mustUnderstand="1" xmlns:o="">
			<u:Timestamp u:Id="_0">
		<trust:RequestSecurityTokenResponseCollection xmlns:trust="">
					<wsu:Created xmlns:wsu="">2013-03-14T07:57:08.620Z</wsu:Created>
					<wsu:Expires xmlns:wsu="">2013-03-14T08:57:08.620Z</wsu:Expires>
				<wsp:AppliesTo xmlns:wsp="">
					<wsa:EndpointReference xmlns:wsa="">
					<Assertion ID="_86845c5a-eaf8-4a75-a921-28456232cc86" IssueInstant="2013-03-14T07:57:08.622Z" Version="2.0" xmlns="urn:oasis:names:tc:SAML:2.0:assertion">
						<ds:Signature xmlns:ds="">
								<ds:CanonicalizationMethod Algorithm=""/>
								<ds:SignatureMethod Algorithm=""/>
								<ds:Reference URI="#_86845c5a-eaf8-4a75-a921-28456232cc86">
										<ds:Transform Algorithm=""/>
										<ds:Transform Algorithm=""/>
									<ds:DigestMethod Algorithm=""/>
							<KeyInfo xmlns="">
							<NameID Format="urn:oasis:names:tc:SAML:1.1:nameid-format:unspecified">Bob</NameID>
							<SubjectConfirmation Method="urn:oasis:names:tc:SAML:2.0:cm:bearer">
								<SubjectConfirmationData NotOnOrAfter="2013-03-14T08:02:08.622Z"/>
						<Conditions NotBefore="2013-03-14T07:57:08.620Z" NotOnOrAfter="2013-03-14T08:57:08.620Z">
						<AuthnStatement AuthnInstant="2013-03-14T07:57:08.559Z">
					<SecurityTokenReference b:TokenType="" xmlns="" xmlns:b="">
						<KeyIdentifier ValueType="">_86845c5a-eaf8-4a75-a921-28456232cc86</KeyIdentifier>
					<SecurityTokenReference b:TokenType="" xmlns="" xmlns:b="">
						<KeyIdentifier ValueType="">_86845c5a-eaf8-4a75-a921-28456232cc86</KeyIdentifier>

3. Access Token Request

Having received a SAML assertion which identifies the resource owner user an OAuth 2.0 access token will be requested directly at the Gateway system where the OData service is hosted on.

Authorization: Basic TE...
Content-Type: application/x-www-form-urlencoded;charset=UTF-8
Content-Length: 4534


4. Access Token Response

After successful authentication of the OAuth 2.0 client (the App in this case) and the resource owner an access token is sent back. This access token indicates that it's valid for OData service ZLEAVEREQUESTAPPR_0001 (meaning approval service in first version). The access token is now used for all proceeding requests. The initial roundtrip to the Security Token Service and the OAuth 2.0 Token Endpoint at the Gateway system is not needed anymore as long as the access token is still valid. Therefore in a productive scenario it's recommended to have a long access token validity.

HTTP/1.1 200 OK
Date: Thu, 14 Mar 2013 08:15:40 GMT
Server: SAP NetWeaver Application Server / ABAP 731
content-type: application/json; charset=utf-8
content-length: 142
cache-control: no-store
pragma: no-cache

{ "access_token":"AFBWmAGzHtKjj-tfpRXSiMPdKUDqd88SFxrzwcxRGuOIdmH7","token_type":"Bearer","expires_in":"600","scope":"ZLEAVEREQUESTAPPR_0001"}

5. OData Service Request

The access token will now be used in the HTTP Bearer authorization header to access the service.

Authorization: Bearer AFBWmAGzHtKjj-tfpRXSiMPdKUDqd88SFxrzwcxRGuOIdmH7

When performing change operations (HTTP POST, PUT, DELETE), prior to the OData service access an XSRF (CSRF) token needs to be fetched. This can be done using the OAuth 2.0 access token.

6. OData Service Response

HTTP/1.1 200 OK
Date: Thu, 14 Mar 2013 08:15:40 GMT
Server: SAP NetWeaver Application Server / ABAP 731
content-type: application/atomsvc+xml
content-length: 877
dataserviceversion: 2.0
set-cookie: sap-usercontext=sap-client=001; path=/

<?xml version="1.0" encoding="utf-8"?><app:service xml:lang="en" xml:base="" ...


  1. Former Member



    We are trying to call a few oData POST services from a non sap Web UI. Can we please get some help on this.


    Thanks & Regards


  2. Hello,

    If I go and check who has approved the leave request. Which user id gets updated in the table. Is it 'LEAVAPP' or Manager's user id (In this example Bob).