Building a Spotify web application Using APEX
This presentation focuses on integrating Spotify's REST API with Oracle APEX, showcasing OAuth2 flows, data synchronization, and utilizing APEX REST Data Sources to create a secure and user-friendly web application.
Download Presentation

Please find below an Image/Link to download the presentation.
The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author.If you encounter any issues during the download, it is possible that the publisher has removed the file from their server.
You are allowed to download the files provided on this website for personal or commercial use, subject to the condition that they are used lawfully. All files are the property of their respective owners.
The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author.
E N D
Presentation Transcript
Building a Spotify web application using APEX Andr van der Put 30-9-2021
About me Software developer at Open-Fine Oracle developer since 1997 APEX developer since 2009 a.v.d.put@open-fine.nl linkedin.com/in/andrevanderput/ 2 30-9-2021 Building a Spotify web application using APEX
Why Spotify? Has a REST API that uses authentication Could also be Jira, LinkedIn, 3 30-9-2021 Building a Spotify web application using APEX
Why this presentation? APEX and Web Services Documentation focuses on Oracle REST Data Services Little to be found on APEX and external web services APEX and authenticated external web services ??? 4 30-9-2021 Building a Spotify web application using APEX
Overview Apex REST Data Sources (formerly Web Source Modules) Spotify Web API OAuth2 flows Examples 5 30-9-2021 Building a Spotify web application using APEX
Oracle Cloud Free Tier Autonomous Database Call external web services from APEX All web services must be secured. Only HTTPS services are supported on the default port (443). Your Application Express instance is pre- configured with an Oracle Wallet that contains more than 90 of the most common trusted root and intermediate SSL certificates. Each Autonomous Transaction Processing instance is preconfigured with a network access control list (ACL) to permit outbound web service calls from Application Express. No further configuration by application developers is necessary. 6 30-9-2021 Building a Spotify web application using APEX
APEX REST Data Sources No authentication, easy to create Example: RSS feed 7 30-9-2021 Building a Spotify web application using APEX
APEX REST Data Sources REST Data Source can be used in PL/SQL e.g. to fill table with Web Source data Use APEX_EXEC.OPEN_WEB_SOURCE_QUERY and APEX_EXEC.NEXT_ROW Since 20.2: Data Synchronization 8 30-9-2021 Building a Spotify web application using APEX
Spotify Web API https://developer.spotify.com/documentation/web-api/reference/ 64 web endpoints Authorization via OAuth2 9 30-9-2021 Building a Spotify web application using APEX
Authorization https://developer.spotify.com/documentation/general/guides/authori zation-guide/ 10 30-9-2021 Building a Spotify web application using APEX
OAuth2 Spotify uses 3 OAuth2 flows: Client Credentials Authorization Code Implicit Grant (JavaScript client) 21 of the 64 web endpoints are accessible via Client Credentials APEX only supports Client Credentials 11 30-9-2021 Building a Spotify web application using APEX
Client Credentials flow 12 30-9-2021 Building a Spotify web application using APEX
Client Credentials in Spotify https://developer.spotify.com/dashboard/applications Create a client ID 13 30-9-2021 Building a Spotify web application using APEX
Client Credentials in APEX Authentication in REST Data Source Example: Get Categories 14 30-9-2021 Building a Spotify web application using APEX
Example: Get Categories GET https://api.spotify.com/v1/browse/categories { "categories": { "items": [ { "id": "toplists", "name": "Top Lists" }, { "id": "hiphop", "name": "Hip Hop" }, ..... ..... ] } } 15 30-9-2021 Building a Spotify web application using APEX
Authorization Code flow User login and approval Scopes Callback URL Refresh token 16 30-9-2021 Building a Spotify web application using APEX
17 30-9-2021 Building a Spotify web application with APEX
Authorization Code in APEX 2 options Use Social Sign-in function of APEX (Almost) no coding APEX authentication through Spotify account No refresh token Create your own code Use any APEX authentication Refresh token available 18 30-9-2021 Building a Spotify web application using APEX
Authorization Code in Spotify (option 1) Register Callback URL From APEX API package: apex_authentication.callback 19 30-9-2021 Building a Spotify web application using APEX
Authorization Code in APEX (option 1) Create Authentication Scheme Type: Social Sign-In Credentials in Credential Store (client_id and client_secret) 20 30-9-2021 Building a Spotify web application using APEX
Authorization Code in APEX (option 1) Get Access token in Post-Authentication Procedure 21 30-9-2021 Building a Spotify web application using APEX
Authorization Code in APEX Make requests to the Spotify Web API REST Data Source with access token in Authorization header Example: Get a List of Current User's Playlists 22 30-9-2021 Building a Spotify web application using APEX
Example: Get a List of Current User's Playlists GET https://api.spotify.com/v1/me/playlists { "href": "https://api.spotify.com/v1/users/wizzler/playlists", "items": [ { "id": "53Y8wT46QIMz5H4WQ8O22c", "name": "Wizzlers Big Playlist", "tracks": { "href": , "total": 30 }, "type": "playlist", }, ], "limit": 9, "next": null, "offset": 0, "previous": null, "total": 9 } 23 30-9-2021 Building a Spotify web application with APEX
Authorization Code in APEX (option 2) Callback URL Three parameters: code, state and error Can be made via ORDS 24 30-9-2021 Building a Spotify web application using APEX
Authorization Code in Spotify (option 2) Register Callback URL 25 30-9-2021 Building a Spotify web application using APEX
Authorization Code in APEX (option 2) Make request to the Spotify accounts service to get tokens Via APEX_WEB_SERVICE.MAKE_REST_REQUEST { } "access_token": "NgCXRK...MzYjw", "token_type": "Bearer", "scope": "user-read-private user-read-email", "expires_in": 3600, "refresh_token": "NgAagA...Um_SHo" Reconnect to APEX session 26 30-9-2021 Building a Spotify web application using APEX
Authorization Code in APEX (option 2) Call authorize service, parameters: In callback procedure: Call web API s using access token client_id redirect URL (callback) scope state (APEX session ID) call token URL, parameters: store retrieved tokens in table, key: session ID redirect to APEX session using session ID code client_id client_secret 27 30-9-2021 Building a Spotify web application using APEX
Authorization Code in APEX (option 2) Refresh token Make request to the Spotify accounts service Via APEX_WEB_SERVICE.MAKE_REST_REQUEST Refresh token in POST Client ID and Client Secret BASE64 encoded in Header 28 30-9-2021 Building a Spotify web application using APEX
Summary Client credentials flow REST Data Sources No coding necessary Authorization code flow Use Social Sign-in Create custom callback code No coding necessary for authorization Limited session length (1 hour) Coding required for authorization Indefinite session length 29 30-9-2021 Building a Spotify web application using APEX
Questions? 30 30-9-2021 Building a Spotify web application using APEX