on 2021 Aug 30 1:17 AM
hello. all the sample ABAP code snippets i found for calling OAuth2 rest service were with OA2C
i am on older version, i dont have the method execute_cc_flow in class cl_oauth_client. my version in srm 750 sp 20. im told tat i cant use oa2c.
so i have written below code to get the token and i am getting error http 400 "Missing Grant_type"
im looking for how to pass key and parameter , Grant_type = Client credentials while calling the method. Could you please help me with this and tell me if u think im doing right?
thanks in advance.
data: lo_http_client type ref to if_http_client,
lo_rest_client type ref to cl_rest_http_client,
lo_request type ref to if_rest_entity,
lo_response type ref to if_rest_entity,
lv_url type string,
lv_body type string.
lv_url = 'https://xxxxx.us20.hana.ondemand.com/oauth/token'.
cl_http_client=>create_by_url(
exporting
url = lv_url
importing
client = lo_http_client
exceptions
argument_not_found = 1
plugin_not_active = 2
internal_error = 3
others = 4 ).
lo_http_client->propertytype_logon_popup = lo_http_client->co_disabled.
data l_username type string.
data l_password type string.
l_username = 'sb-mdm-mdmdev!t557'.
l_password = 'RhefQVuQe3sDdc4zg1X1ATSQF5g='.
call method lo_http_client->authenticate
exporting
username = l_username
password = l_password.
* Create REST client instance
create object lo_rest_client exporting io_http_client = lo_http_client.
* Create request instance
lo_request = lo_rest_client->if_rest_client~create_request_entity( ).
lo_http_client->request->set_header_field( name = 'grant_type' value = 'client_credentials' ).
lo_request->set_content_type( exporting iv_media_type = if_rest_media_type=>gc_appl_www_form_url_encoded ).
* HTTP Post
lo_rest_client->if_rest_resource~post( lo_request ).
* HTTP response
lo_response = lo_rest_client->if_rest_client~get_response_entity( ).
lo_response->set_content_type( exporting iv_media_type = if_rest_media_type=>gc_appl_json ).
* HTTP return status
data(http_status) = lo_response->get_header_field( '~status_code' ).
* HTTP JSON return string
data(json_response) = lo_response->get_string_data( ).
Help others by sharing your knowledge.
AnswerRequest clarification before answering.
Hi Bhakti,
You may try out the client credential options with POSTMAN once to confirm if its working standalone as desired or there is any issue with custom code.
Regarding the OA2C_CONFIG/OA2C_GRANT, I had come across a very nice and detailed wiki page which has step by step details of using 'Authorization code' option and steps relevant to OA2C_GRANT.
https://wiki.scn.sap.com/wiki/display/Security/Access+Google+APIs+using+the+OAuth+2.0+Client+API
This would help you.
Note -
In order to be able to use OA2C_GRANT, you would need the below authorization granted from security perspective
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
68 | |
9 | |
7 | |
7 | |
6 | |
6 | |
5 | |
4 | |
4 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.