hipchat oauth token internal server error - oauth

I follow hipchat site and try to get an add-on token
https://developer.atlassian.com/hipchat/guide/hipchat-rest-api/api-access-tokens?_ga=2.94621780.975509804.1497491262-871504840.1479901346#APIaccesstokens-Add-ongeneratedtokens
I have the following code:
import requests
secret = 'hipchat_secret'
headers = {'Content-Type': 'application/x-www-form-urlencoded',
'Authorization': 'Basic {}'.format(secret)}
url = 'https://api.hipchat.com/v2/oauth/token?grant_type=client_credentials&scope=send_notification+admin_room'
res = requests.post(url, headers=headers)
But it gives me a 500 Internal Server Error. What is wrong with my code?

The mistake was I used v1 token.
It works perfect when I switch to v2

Related

How to authenticate a call to a private google cloud function from a container on a VM on the vpc?

In GCP, I have a Compute Engine VM on the default VPC running docker. I have a container app (python fastAPI web app) that needs to call a private cloud function to post some data using requests.
head = {
'Content-Type': 'application/json;charset=UTF-8',
'Accept': 'application/json',
'Authorization': 'Bearer ' + token
}
resp = requests.post(url,
data = msgObj,
headers = head,
timeout=1.50
)
This is all working fine, but the call to the private cloud function needs Bearer Authorization. I can't seem to find a way to programmatically get this token. I can get a token for testing by using
gcloud auth print-identity-token > token.txt on the host VM. This works, but is not acceptable for production use.
Any thoughts?
I have tried to use a token generated by another private cloud function that posts data to the container app.
const auth = new GoogleAuth();
const token = await auth.getAccessToken();
But this token didn't work. (401 Unauthorized)
Getting the token via gcloud (see above) from the VM host works, but is obviously hardcoded and will not work for long - only testing.
This use case (calling a private cloud function from a container) doesn't seem to be covered by anything I can find. There is a video on how to do this from google but was useless - basically saying to use the gcloud approach above.
The answer was actually straightforward once I found it from several clues.
add google-auth=2.6.2 to the requirements doc for the container
add the following to your container code
import google.auth.transport.requests
import google.oauth2.id_token
audience = function_url
auth_req = google.auth.transport.requests.Request()
id_token = google.oauth2.id_token.fetch_id_token(auth_req, audience)
Then use the id_token in the header for the function call
head = {
'Content-Type': 'application/json;charset=UTF-8',
'Accept': 'application/json',
'Authorization': 'Bearer ' + id_token
}
resp = requests.post(audience,
data = msgObj,
headers = head
)

Ionic post API error unauthorized

I use Ionic to build App, I would like post on API that I prepare I test
API using postman it works correctly
but when I use Ionic face an error 405 Method not allowed
this is the response for request:
{"Message":"The requested resource does not support HTTP method 'OPTIONS'."}
I got status 200 on postman but 405 using ionic
Postman:
This is my code:
var auth = 'bearer ' + Token;[enter image description here][1]
let headers = new Headers({
'Content-Type': 'application/json',
'withCredentials': 'true',
'Authorization': auth
});
return this.http.post('http://abdalrahmannada-001-site1.htempurl.com/api/Rabbit/AddRabbit', { headers: headers })
.map(response => response);
this problem relate to server side
you should want from admin server provider to enable http option for you
most hosting disable this for security

AADSTS90014: The request body must contain the following parameter: 'grant_type'

I am trying to send a post request to receive my access token from https://login.microsoftonline.com/common/oauth2/v2.0/token. When I tried this in my REST client, it works, but when I try to integrate it to my app, it sends me a error 400 Bad Gateway, with the message AADSTS90014: The request body must contain the following parameter: 'grant_type'. I tried searching for answers, and found out that I need to implement headers in my post request, so I did that, but it still won't work. Any ideas?
Http Imports:
import { HttpClient, HttpHeaders, HttpRequest } from '#angular/common/http';
Call to post request:
var url=this.outlook_authentification_endpoint+"token";
var query_parameters=JSON.stringify({grant_type:"authorization_code", client_id:this.outlook_client_id, code: this.outlook_user_code, client_secret: this.outlook_secret_key, redirect_uri: this.outlook_redirect_uri});
const httpOptions = {
headers: new HttpHeaders({
'Content-Type': 'application/x-www-form-urlencoded'
})
};
this.query_service.postOutlook(url, query_parameters, httpOptions, (data)=>
{
console.log(data);
});
Call to the post function:
public postOutlook(url, query, headers, callback)
{
this.operation_pending=true;
this.http_client.post(url,query, headers).subscribe((data)=>
{
this.operation_pending=false;
callback(data);
});
}
Can anyone see where my error is?
You are using wrong OAuth2 flow (the way of getting tokens). You are using the Auth code grant, which cannot be used in browser applications, because you would have to keep your client secret in JavaScript, which means make it public. So you cannot access the /token endpoint either.
You should use the Implicit grant, which is designed for browser applications. Then you get tokens right into your Angular application without the need of going to the /token endpoint.

How to make a pre-emptive basic authentication call using savon client in ruby?

I am doing the following code in savon but unable to do as it requires pre-emptive authorization. I have verified in soapUI but unable to run in savon.
Could somebody help?
client = Savon.client(ssl_verify_mode: :none) do
wsdl '/Users/sp/jda_notifications/TransportationManagerService.wsdl'
endpoint 'http://localhost:8088/webservices/services/TransportationManager'
basic_auth('VENTURE', 'VENTURE')
end
I got the exact same problem
here the solution :
realm = Base64.strict_encode64("VENTURE:VENTURE")
client = Savon.client(
wsdl:'/Users/sp/jda_notifications/TransportationManagerService.wsdl',
headers: { 'Authorization' => "Basic #{realm}"}
)
We have to use headers which edit http headers and not soap_header.

WSO2 Oauth2 Authentication - Provided Authorization Grant is invalid

I'm testing the WSO2 Identity server using the Oauth 2.0 with a Python login application. The routine which I adjusted from another IdP server, throws an error at the token authorization step, after successfully passing through step 1 which is obtaining the request code. The error returning from the WSO2 server is:
"Provided Authorization Grant is invalid"
Console Log
*** start of login ***
Code received = 23618215e0ee701b973f548a3f8e7dda
Token Request Answered = <Response [400]>
Token Request Text = {"error":"invalid_grant","error_description":"Provided Authorization Grant is invalid."}
Token Request URL = https://extbasicpacman05.podc.sl.edst.red.com:9443/oauth2/token
Token Request Encoding = None
Code:
#print "Send Token Request now"
# prepare lookup of token using code as input
verify='/home/claudef/tmp/oauth_2/oauth/wso2.pem'
url = "https://extbasicpacman05.podc.sl.edst.red.com:9443/oauth2/token"
payload = { 'client_id': client_id, 'client_secret': client_secret, 'grant_type': 'authorization_code', 'code': str(code), 'redirect_uri': 'http://localhost/resources/oauth2Callback' }
urllib.urlencode(payload)
headers = { 'application' : 'x-www-form-urlencoded' }
r = requests.post(url, data=payload, headers=headers, verify=verify)
print "Token Request Answered = " + str(r)
print "Token Request Text = " + str(r.text)
print "Token Request URL = " + str(r.url)
print "Token Request Encoding = " + str(r.encoding)
Any hint how to fix the authorization grant using a code value is welcome.
Just identified the error cause, indeed its a coding error, as the callback URL contained a missing port definition. I've corrected the statements to the new setting and the token returned successfully from the WSO2 server. The problem is solved.
The error message "invalid grant" is somehow confusing, maybe a suggestion
for future improvements.
verify='/home/claudef/tmp/oauth2/oauth/wso2.pem'
url = "https://extbasicpacman05.podc.sl.edst.red.com:9443/oauth2/token"
payload = { 'client_id': client_id, 'client_secret': client_secret, 'grant_type': 'authorization_code', 'code': str(code), 'redirect_uri': 'http://localhost:8080/resources/oauth2Callback'}
urllib.urlencode(payload)
headers = { 'application' : 'x-www-form-urlencoded' }
r = requests.post(url, data=payload, headers=headers, verify=verify)

Resources