<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: XSUAA BTP Service Implementation for Custom Python APP in Application Development and Automation Discussions</title>
    <link>https://community.sap.com/t5/application-development-and-automation-discussions/xsuaa-btp-service-implementation-for-custom-python-app/m-p/14017104#M2038530</link>
    <description>&lt;P&gt;What are the other services you have in the manifest file, i can see that it is blocked for viewing?&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 14 Feb 2025 11:15:13 GMT</pubDate>
    <dc:creator>pianistprogrammer</dc:creator>
    <dc:date>2025-02-14T11:15:13Z</dc:date>
    <item>
      <title>XSUAA BTP Service Implementation for Custom Python APP</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/xsuaa-btp-service-implementation-for-custom-python-app/m-p/13991148#M2038321</link>
      <description>&lt;P&gt;&lt;STRONG&gt;Introduction&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;In the realm of SAP Business Technology Platform (BTP), XSUAA (Extended Services for User Authentication and Authorization) plays a crucial role in managing secure access to applications. Integrating XSUAA with a custom Python Flask app can significantly enhance the security by leveraging OAuth2 and JWT tokens for authentication and authorization. This blog post will guide you through the process of setting up and integrating XSUAA with a Python Flask application.&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Pre-requisites&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;Before diving into the implementation, ensure you have the following:&lt;/P&gt;&lt;P&gt;SAP BTP Account: Access to an SAP BTP account with necessary entitlements.&lt;BR /&gt;Python: Installed on your local machine (preferably Python 3.6+). or we can use BAS as well&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Step 1: Configuring XSUAA&lt;/STRONG&gt;&lt;BR /&gt;Set Up XSUAA Service in SAP BTP:&lt;/P&gt;&lt;P&gt;Log in to your SAP BTP Cockpit.&lt;BR /&gt;Navigate to your subaccount and create an instance of the XSUAA service.&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Ace_D_0-1737386420643.png" style="width: 400px;"&gt;&lt;img src="https://community.sap.com/t5/image/serverpage/image-id/214479i7B1E8A8BFE5FAF2F/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Ace_D_0-1737386420643.png" alt="Ace_D_0-1737386420643.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;Subscribe the service and generate the service key which will be used later for connecting to this service&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Ace_D_1-1737386784753.png" style="width: 400px;"&gt;&lt;img src="https://community.sap.com/t5/image/serverpage/image-id/214483iCF1CEE2BF4AEC398/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Ace_D_1-1737386784753.png" alt="Ace_D_1-1737386784753.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;Service key looks like this.&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Ace_D_2-1737386892205.png" style="width: 400px;"&gt;&lt;img src="https://community.sap.com/t5/image/serverpage/image-id/214485iB4C1DBBF7C85F0C4/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Ace_D_2-1737386892205.png" alt="Ace_D_2-1737386892205.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;It consists of client secret id and password.&lt;/P&gt;&lt;P&gt;Once this steps are done we can proceed with python implementation&amp;nbsp;&lt;/P&gt;&lt;P&gt;lets create a flask based Flask python application which is hosted on cloud foundry of BTP&lt;/P&gt;&lt;P&gt;To host a python file over the BTP we need below files mandatory.&lt;/P&gt;&lt;P&gt;1. Main Python file(logic)&lt;/P&gt;&lt;P&gt;2. Requirements.txt file&lt;/P&gt;&lt;P&gt;3. Manifest.yml file&lt;/P&gt;&lt;P&gt;4. Runtime.txt file&lt;/P&gt;&lt;P&gt;File structure will look like this&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Ace_D_3-1737387190905.png" style="width: 400px;"&gt;&lt;img src="https://community.sap.com/t5/image/serverpage/image-id/214487iC41865457A49C372/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Ace_D_3-1737387190905.png" alt="Ace_D_3-1737387190905.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;Lets quickly create all this file for a basic implementation.&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;One point to Note here: To test XSUAA Service we need to push file to the CF, we cannot test it locally.&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;So we will create 3 end points with flask in python&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Ace_D_4-1737387803286.png" style="width: 400px;"&gt;&lt;img src="https://community.sap.com/t5/image/serverpage/image-id/214492i3C51CFB8A7220590/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Ace_D_4-1737387803286.png" alt="Ace_D_4-1737387803286.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;Herer we are importing all the libraries that are needed for this implementation.&lt;/P&gt;&lt;P&gt;name will be the XSUAA BTP service name.&lt;/P&gt;&lt;P&gt;Since this doesn't works in local environment we will push this to CF after all routes are done.&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;APPEnv&lt;/STRONG&gt; is the cloud foundry environment once app is deployed over CF so from the env we are using the XSUAA service that we created in the previous section.&lt;/P&gt;&lt;P&gt;1. To generate the Token&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Ace_D_5-1737387961852.png" style="width: 400px;"&gt;&lt;img src="https://community.sap.com/t5/image/serverpage/image-id/214495iB513D9E964BC49BA/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Ace_D_5-1737387961852.png" alt="Ace_D_5-1737387961852.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;This end point will help to get a Auth token&amp;nbsp;&lt;/P&gt;&lt;P&gt;2. Validate the Generated Token&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Ace_D_6-1737388048621.png" style="width: 400px;"&gt;&lt;img src="https://community.sap.com/t5/image/serverpage/image-id/214497i4B1F68457E4E64EC/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Ace_D_6-1737388048621.png" alt="Ace_D_6-1737388048621.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;This end point help us to validate any token coming from external source&lt;/P&gt;&lt;P&gt;3. How to make public url private with this bearer generated token.&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Ace_D_7-1737388110601.png" style="width: 400px;"&gt;&lt;img src="https://community.sap.com/t5/image/serverpage/image-id/214499i18AB22F0844E12EF/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Ace_D_7-1737388110601.png" alt="Ace_D_7-1737388110601.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;This is main Logic end point. generally for development we don't create end points to generate and validate.&lt;/P&gt;&lt;P&gt;Just for testing we have created here.&lt;/P&gt;&lt;P&gt;As you can see if i dont keep a validation over the /testroute it will be a public url but now i have defined a method to check validity of the token. So it will first validate than only my actual logic will give result.&lt;/P&gt;&lt;P&gt;Overall Python code looks like&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Ace_D_8-1737388366909.png" style="width: 400px;"&gt;&lt;img src="https://community.sap.com/t5/image/serverpage/image-id/214502i1D6B6646B2C72CD1/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Ace_D_8-1737388366909.png" alt="Ace_D_8-1737388366909.png" /&gt;&lt;/span&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Ace_D_9-1737388384606.png" style="width: 400px;"&gt;&lt;img src="https://community.sap.com/t5/image/serverpage/image-id/214503i4AAAD2176E3378F5/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Ace_D_9-1737388384606.png" alt="Ace_D_9-1737388384606.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;once main logic is done we will create 3 other required files.&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Manifest.yml&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Ace_D_10-1737388580953.png" style="width: 400px;"&gt;&lt;img src="https://community.sap.com/t5/image/serverpage/image-id/214504i4EB0C7CECA4DCC32/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Ace_D_10-1737388580953.png" alt="Ace_D_10-1737388580953.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;Manifest file contains all the necessary information needed for the deployment of the python app.&lt;/P&gt;&lt;P&gt;name : The name of the python application&lt;/P&gt;&lt;P&gt;Memory and disk quotes: This are the space your application going to occupy over the CF&lt;/P&gt;&lt;P&gt;Command: The main file which is gonna execute once your app is deployed.&lt;/P&gt;&lt;P&gt;services: Here we gonna link the XSUAA service name which is there on the BTP&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Requirements.txt&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Ace_D_11-1737388960916.png" style="width: 400px;"&gt;&lt;img src="https://community.sap.com/t5/image/serverpage/image-id/214511i1FF8DB4C653728A2/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Ace_D_11-1737388960916.png" alt="Ace_D_11-1737388960916.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;List of all the libraries needed for the application.&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Runtime.txt&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Ace_D_13-1737389028385.png" style="width: 400px;"&gt;&lt;img src="https://community.sap.com/t5/image/serverpage/image-id/214514iF5F34DCFA69B7DEC/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Ace_D_13-1737389028385.png" alt="Ace_D_13-1737389028385.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This consists of the runtime python environment version which is going to be used by CF.&lt;/P&gt;&lt;P&gt;Once all this files are setup. You can push them to the CF.&lt;/P&gt;&lt;P&gt;For this I am using BAS. SO i just need to login into my CF and go to the root folder of the python app.&lt;/P&gt;&lt;P&gt;Once I am in the root folder i can just deploy by using CF Push command in the command terminal.&lt;/P&gt;&lt;P&gt;Once the app is deployed successfully you will get the complete URL in the command terminal or else also you can get from the BTP as well.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;DIV class=""&gt;&amp;nbsp;&lt;/DIV&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Ace_D_15-1737389462677.png" style="width: 400px;"&gt;&lt;img src="https://community.sap.com/t5/image/serverpage/image-id/214517iDA1882972B68DBDF/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Ace_D_15-1737389462677.png" alt="Ace_D_15-1737389462677.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;You will get the above logs once python app is successfully deployed.&lt;/P&gt;&lt;P&gt;Now lets head to chrome to do some basic testing.&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Ace_D_16-1737389542137.png" style="width: 400px;"&gt;&lt;img src="https://community.sap.com/t5/image/serverpage/image-id/214518i7BED14318A62EFD8/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Ace_D_16-1737389542137.png" alt="Ace_D_16-1737389542137.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;The app is working as expected.&lt;/P&gt;&lt;P&gt;Now you can use this token and send it to the /validate root or /testroute to test with postman.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Ace_D_17-1737389680636.png" style="width: 400px;"&gt;&lt;img src="https://community.sap.com/t5/image/serverpage/image-id/214520i980724B17022D576/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Ace_D_17-1737389680636.png" alt="Ace_D_17-1737389680636.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;Just use with bearer auth the generated token and call your python routes.&lt;/P&gt;&lt;P&gt;Hence we successfully converted public Api calls to private with BTP XSUAA service.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 20 Jan 2025 16:19:44 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/xsuaa-btp-service-implementation-for-custom-python-app/m-p/13991148#M2038321</guid>
      <dc:creator>Ace_D</dc:creator>
      <dc:date>2025-01-20T16:19:44Z</dc:date>
    </item>
    <item>
      <title>Re: XSUAA BTP Service Implementation for Custom Python APP</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/xsuaa-btp-service-implementation-for-custom-python-app/m-p/13993915#M2038335</link>
      <description>&lt;P&gt;&lt;STRONG&gt;Just a minor correction in the blog since we are binding the application with the service we don't need to generate service key as mentioned above.&lt;/STRONG&gt; Application bounded will use the credentials from the service. External services need the service key generation.&lt;/P&gt;</description>
      <pubDate>Thu, 23 Jan 2025 07:56:05 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/xsuaa-btp-service-implementation-for-custom-python-app/m-p/13993915#M2038335</guid>
      <dc:creator>Ace_D</dc:creator>
      <dc:date>2025-01-23T07:56:05Z</dc:date>
    </item>
    <item>
      <title>Re: XSUAA BTP Service Implementation for Custom Python APP</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/xsuaa-btp-service-implementation-for-custom-python-app/m-p/14017104#M2038530</link>
      <description>&lt;P&gt;What are the other services you have in the manifest file, i can see that it is blocked for viewing?&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 14 Feb 2025 11:15:13 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/xsuaa-btp-service-implementation-for-custom-python-app/m-p/14017104#M2038530</guid>
      <dc:creator>pianistprogrammer</dc:creator>
      <dc:date>2025-02-14T11:15:13Z</dc:date>
    </item>
    <item>
      <title>Re: XSUAA BTP Service Implementation for Custom Python APP</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/xsuaa-btp-service-implementation-for-custom-python-app/m-p/14026007#M2038602</link>
      <description>&lt;P&gt;Hey &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;BR /&gt;Thanks for this tutorial. How to get your hands on other attributes expect the Email and Name for Example the Phone Number, Language or the custom attributes? How can i query them in the code?&lt;/P&gt;</description>
      <pubDate>Mon, 24 Feb 2025 14:16:29 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/xsuaa-btp-service-implementation-for-custom-python-app/m-p/14026007#M2038602</guid>
      <dc:creator>SuperMario94</dc:creator>
      <dc:date>2025-02-24T14:16:29Z</dc:date>
    </item>
  </channel>
</rss>

