When working through section 6.1 of the Recognition of hand-written digits with IBM Watson Machine Learning notebook, calling the Watson Machine Learning REST API to get the list of published models using:
GET /v3/wml_instances/{instance_id}/published_models
endpoint, there is a authorization (401) error with the following response text:
{"trace":"-1xmid60eblabs","errors":[{"code":"invalid_token_format","message":"Invalid token format. Bearer token format should be used.","target":{"type":"header","name":"Authorization"}}]}
The previous REST API call in the notebook to get the instance details using the authorization token returned from the /v3/identity/token endpoint worked ok.
Looks like an error in the notebook. Did the API authorization scheme change breaking the notebook?
This endpoint in the REST API appears to be expecting authentication of the form Authorization: <type> <credentials> per W3C in HTTP 1.0
I updated the notebook code to add the type in the Authorization field of the header:
header = {'Content-Type': 'application/json', 'Authorization': 'Bearer ' + mltoken}
The rest of the Watson Machine Learning API calls to create the online deployment and score new data use the same header in the notebook and all execute correctly.
Related
I use self hosted Jira and I'm currently trying to connect to the Jira api using a python script (and the requests library) having 2fa enabled by my organization. I'm not an admin of the project and after creating a personal access token and using it as a Bearer token I only got so far to get a response from the server telling me to put in the OTP to proceed.
I was thinking whether I could possibly pass the OTP as part of the authorization header when making the request to the api but couldn't find any useful hints on how to do that. I have also been looking into OAuth tokens but from my understanding I'm unable to create one since I don't have the option to create an application link within Jira (since I'm not an admin).
Does anyone have an idea on how I could manage to establish the connection to the api?
Any help would be appreciated!!
Cheers,
Liz
Hey #Liz try this project for inspiration - https://github.com/dren79/JiraScripting_public
I built it out on the below examples from the API documentation.
#This code sample uses the 'requests' library:
#http://docs.python-requests.org
import requests
from requests.auth import HTTPBasicAuth
import json
url = "https://your-domain.atlassian.net/rest/api/3/issue/{issueIdOrKey}"
auth = HTTPBasicAuth("email#example.com", "<api_token>")
headers = {
"Accept": "application/json"
}
response = requests.request(
"GET",
url,
headers=headers,
auth=auth
)
print(json.dumps(json.loads(response.text), sort_keys=True, indent=4, separators=(",", ": ")))
I am trying to build a Custom Connector in the Power Platform to connect to the BMC Helix (formerly Remedy) system to create work orders and such. I am using OAuth2 and was given a callback URL, auth URL, token URL, client ID and client secret.
I went to create a connector from scratch. I populated the fields, but I wasn't sure what to put for the 'Refresh URL', so I used the token URL there too.
I am trying to accomplish testing this connector and my successful test would be to get a JWT from doing a POST to the /api/jwt/login endpoint of BMC Helix. It should return a JWT which I can use to make subsequent calls.
Upon testing this, I go to create a connection, but a window opens (which I believe should be a prompt for authentication), but instead it contains an error saying 'unauthorized_client' coming back from the BMC Helix system at the /rsso/oauth2/authorize endpoint. It also contains a property within the URL of redirect_uri = https://global.consent.azure-apim.net/redirect.
Is there something on the Helix side I need to further configure? Not sure why I am getting this....
It sounds like you need TWO METHODS in your connector. A POST to call the token server, a GET (or another POST) to call the API (using the token received from Call 1).
One approach I've successfully used in the past is:
Use Postman to get your token server call working with OAUTH
Then use Postman to get your subsequent API calls working with the token appended
Save both requests to a single Postman collection
Export the Postman collection (as a V1 (deprecated) if I recall correctly)
Import this collection into PowerApps Custom Connector (create new/import from Postman Collection)
You'll have to massage it a bit after import, but it will give you a good headstart and you're starting from a known-good place (working Postman calls)
Good luck!
I am able to generate an oauth2 access token (from a refresh token), which I believe should give me the ability to access the youtube data api functionally to delete/upload content.
Using python and the youtube api I need to delete and upload a (new) video to youtube periodically, say hourly.
All google python samples I've found seem to call the "DENY/ALLOW" screen which requires a copy/paste back in the calling app.
I can do this occasionally but otherwise want the process to be automated. I've read about service accounts which, which according to the linked post, are not supported by the youtube api. Offline access et.al. is also mentioned but in somewhat abstract terms i.e. no concrete python examples (that I have yet found). Another source mentioned an http get like below:
"GET access_token=ya29.GlxBBS89....ast987&part=snippet&mine=true"
but the following in python doesn't seem to work returning "response [400]" (bad request)
url = 'https://www.googleapis.com/youtube/v3/channels'
args = 'access_token: ' + token var + ', part: snippet, mine: true'
get_token = requests.get(url, data = args)
I have used Can we use google youtube data api without OAuth (and others) to get to this stage but need clarification for the next step.
**********************************Update*********************************
I have found that I can only generate access tokens for clients credentials configured as web apps. I am writing a desktop app so I may be barking up the wrong tree.
Or learning Django...
I found examples at https://developers.google.com/youtube/v3/guides/auth/installed-apps that helped.
curl -H "Authorization: Bearer <access_token>" https://www.googleapis.com/youtube/v3/channels?part=snippet&mine=true
curl https://www.googleapis.com/youtube/v3/channels?access_token=<access_token>&part=snippet&mine=true
The curl samples especially provided confirmation that I'm reaching the endpoint and returned helpful debugging info. They have exposed other issues which I'll ask in another question.
I am making a POST call to get oAuth token in JMeter. So that I can upload files to Google Drive. Below is my request details in JMeter.
POST https://accounts.google.com/o/oauth2/token
POST data:
client_id=<my_client_id>&auth_uri=https%3A%2F%2Faccounts.google.com%2Fo%2Foauth2%2Fauth&token_uri=https%3A%2F%2Faccounts.google.com%2Fo%2Foauth2%2Ftoken&client_secret=<my_client_secret>&grant_type=authorization_code&redirect_uris=%5B%22urn%3Aietf%3Awg%3Aoauth%3A2.0%3Aoob%22%2C+%22127.0.0.1%3A3000%22%5D%0A&scope=https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fdrive
[no cookies]
Request Headers:
Connection: keep-alive
Content-Type: application/x-www-form-urlencoded
Content-Length: 424
Host: accounts.google.com
User-Agent: Apache-HttpClient/4.5.2 (Java/1.8.0_121)
But I am getting below error. Any help is appreciated. Thanks.
{
:
"error"
: : "invalid_request",
: "error_description" : "Missing required parameter: code"
}
I can not help you with JMeter but I can tell you what the error message means.
The grant_type=authorization_code is the second step in the Oauth2 flow. It has a few required parameters one of them is code.
https://accounts.google.com/o/oauth2/token
code=4/X9lG6uWd8-MMJPElWggHZRzyFKtp.QubAT_P-GEwePvB8fYmgkJzntDnaiAI&client_id={ClientId}.apps.googleusercontent.com&client_secret={ClientSecret}&redirect_uri=urn:ietf:wg:oauth:2.0:oob&grant_type=authorization_code
The code in question is the code that was returned from the initial request for the user to approve the applications access.
I would also like to add that Google has a number of official client libraries that will deal with these calls for you. Using one of those is much easer then trying to understand the Oauth2 flow if you don't need to. If you cant use the library and you are interested in seeing the full Oauth2 flow to google I have a tutorial on it Google 3 legged Oauth2 flow it shows the pure HTTP calls.
I would recommend using Google OAuth Java Client Library from JSR223 Test Elements using Groovy as a programming language, this is the fastest and the easiest way to obtain/refresh OAuth tokens.
See How to Run Performance Tests on OAuth Secured Apps with JMeter article for detailed explanation and an authorization example.
I'm trying to sign a request with OAuth. I read a lot of articles on it, but I don't know how to actually use it right now.
I have this URL: https://userstream.twitter.com/2/user.json And I want to call it for a certain user. I have an app (with Consumer key en secret) and the API key for the account I want to use. So the only thing left to do is sign it.
I used this page: http://hueniverse.com/2008/10/beginners-guide-to-oauth-part-iv-signing-requests/ and got a code block that looked like this one:
GET /photos?size=original&file=vacation.jpg HTTP/1.1
Host: photos.example.net:80
Authorization: OAuth realm="http://photos.example.net/photos",
oauth_consumer_key="dpf43f3p2l4k3l03",
oauth_token="nnch734d00sl2jdk",
oauth_nonce="kllo9940pd9333jh",
oauth_timestamp="1191242096",
oauth_signature_method="HMAC-SHA1",
oauth_version="1.0",
oauth_signature="tR3%2BTy81lMeYAr%2FFid0kMTYa%2FWM%3D"
However, cURL does not accept that. How do I construct something that will work with cURL?
Thanks in advance
EDIT: I don't really need cURL, just comething that I can use with C++ on GNU/Linux
When I've curled a Twitter request from the (Windows) command line, and had to add an OAuth authorization header, I've done it like this:
curl -k "https://userstream.twitter.com/2/user.json" --header "Authorization: OAuth realm=""Twitter API"",oauth_consumer_key=""dpf43f3p2l4k3l03"",oauth_token=""nnch734d00sl2jdk"",oauth_nonce=""kllo9940pd9333jh"",oauth_timestamp=""1191242096"",oauth_signature_method=""HMAC-SHA1"",oauth_version=""1.0"",oauth_signature=""tR3%2BTy81lMeYAr%2FFid0kMTYa%2FWM%3D"""
Of course, if you're using that Java applet, be sure you've set the time as close to the correct time as possible, specified your OAuth credentials, and set the URL part appropriately before substituting the output values into the command line above.
Method: GET
URI Scheme: https
Host Name: userstream.twitter.com
Port: 443
Request Path: /2/user.json
Parameters: [remove all]
Note in the header output that you must manually change the realm to Twitter API, but all the other output values should be correct.
Additionally, this answer has a good selection of C++ Twitter libraries you could try, although the link to the Twitter documentation that lists is out of date -- here's the latest.