I setup ruby on rails backend project on gcloud and now when i am trying to fetch data to a WordPress site using wp_remote_get() method from my json API. the
https://gcloud-assigend-domain.com/api/v1/auth/signin
gcloud is returning me 401 authentication,
although the same thing is working fine at my localhost.
Via wp page i am sending user email and password to API so i can get token-access, client-id, uid and expiry to process.
If anyone aware of this please help me.
I forgot to set the header to 'Content-Type' => 'application/x-www-form-urlencoded',
so i just add the header to wp_remote_post() method and fixed the issue.
'headers' => array(
'Content-Type' => 'application/x-www-form-urlencoded',
),
Related
my project work very well in local server but when i publish it in live hosting everything work except the oauth2 not work and give me Route [login] not defined
i dont khnow were is the problem
my .htaccess
my Route api
Laravel redirect you to login route when API request doesn't authenticated, so add this line to routes/web.php file:
Route::post('login', [ 'as' => 'login', 'uses' => 'LoginController#do']);
I will developing RestFul API with Lumen, but I got some problem.
When I try to get user with email. I got message
"The requested resource /user/test#example.com was not found on this server."
Here my route
$router->get('/{email}', ['as' => 'get', 'uses' => 'UserController#show']);
I try same url in laravel, but It works. I don't know why?
Anyone can suggest or help me, please.
In lumen Routes are like below
$app->get('/user/{email}', 'ThorController#show');
For more information : https://lumen.laravel.com/docs/5.4/routing#route-parameters
Also check your database credentials whether you are using different database for api then laravel application
I'm trying to interact with Keycloak via its REST API. I have the master realm and the default admin user, and a test realm. Firstly, I get an access token for the admin account and test realm:
let data = {
grant_type : 'password',
client_id : 'test-realm',
username : 'admin',
password : 'admin'
};
let headers = {
'Content-Type': 'application/x-www-form-urlencoded'
};
axios.post(
'https://someurl.com:8080/auth/realms/master/protocol/openid-connect/token',
qs.stringify(data),
headers
)
That works ok. Then I try to make a call to create a user (or do anything else) and I get a 401 unauthorized error:
headers = {
'Content-Type': 'application/x-www-form-urlencoded',
'Authorization': `Bearer ${accessToken}`
};
data = {
rep: {
email: "test#email.com",
username: "test#email.com"
},
path: 'test-realm'
};
axios.post('https://someurl.com:8080/auth/admin/realms/test-realm/users',
qs.stringify(data),
headers
)
Is that not the correct way to include the token? Is the access token the one you use for authenticating other API calls? Shouldn't the admin account's token work for authenticating calls to other clients with the master realm? Would it be some setting in the master realm that I have to change in the admin console? Any help appreciated.
I got a 401 error because I generated the offline token by using http://localhost:8080 and then I tried to request the api by using http://keycloak:8080 which is not allowed. Unfortunately the log doesn't tell you that.
To debug JWT tokens I recommend https://jwt.io/
Is that not the correct way to include the token?
This is a correct way.
You just do something incorrectly.
Please, refer for an example from keycloak-request-token Node.js module:
https://github.com/keycloak/keycloak-request-token/blob/master/index.js#L43
You use
client_id : 'test-realm'
but there is
client_id: 'admin-cli'
there.
Also, to create a user, you should use
'Content-Type': 'application/json'
You can refer for Node.js examples of Keycloak REST API here:
https://github.com/v-ladynev/keycloak-nodejs-example/blob/master/lib/adminClient.js
Examples of other useful stuff like:
custom login
storing Keycloak token in the cookies
centralized permission middleware
can be found in the same project: keycloak-nodejs-example
I fixed it by enabling the below "Service Accounts Enabled" button under Settings for admin-cli
I had this issue and solved it by making sure that there is no more than 1 minute between the first and the second API request. So, if you are doing this manually (2 curl requests), the token may expire and you may get error 401. Nevertheless, you should use admin-cli as mentioned above.
I came this issue recently and after struggling for a while i figured. using a realm name containing white spaces will trigger 401 unauthorized error when interacting with via SDKs or API.
IN SUMMARY:
change: realm name
to: realm-name
in my Yii2 application, I try to read data from an REST api, which is protected by an HTTP-Basic - Auth. Additional, a proxy is needed to connet the REST api.
So I chose the Yii httpclient-module to handle this call:
$client = new Client(['baseUrl' => 'http://my.example.com']);
$response = $client->createRequest()
->setMethod('get')
->setUrl('api/session')
->addHeaders(['Authorization' => 'Basic '.base64_encode("user:password")])
->setOptions([
'proxy' => 'proxy.server:8000',
'timeout' => 5,
]);
Running this code, I get an Bad URL in proxy request error-message form the Server.
But if I copy the URL from code to the browser (which also connected to the proxy), everything works fine: the Basic-Auth window comes up.
Is there an error in setting the Authorization tag for the header?
After working a day on this problem, in found the answer. Just a minute after asking my question, but I like to keep that question in the case, that someone has the same problem.
Answer:
The yii2 httpclient uses 2 different transport libraries: Streams (which wokrs without an additional PHP extension and is set as default) and cURL.
Switching to cURL as "transport-type", the code above works fine!
$this->client = new Client([
'baseUrl' => 'http://my.example.com',
'transport' => 'yii\httpclient\CurlTransport'])
I'm using the 'Authenticating without the SoundCloud Connect Screen' method of authentication (see http://developers.soundcloud.com/docs#authentication). That's the method where you provide the whole shebang of credentials -- client_id, client_secret, username, and password. I'm also using the Ruby SDK.
# create client object with app and user credentials
client = Soundcloud.new(:client_id => 'YOUR_CLIENT_ID',
:client_secret => 'YOUR_CLIENT_SECRET',
:username => 'YOUR_USERNAME',
:password => 'YOUR_PASSWORD')
I am trying to use the client to resolve a user.
puts client.get('/resolve', :url => 'https://soundcloud.com/random-username').inspect
However, I keep getting a 401 Unauthorized returned by the client.
I can confirm that I am authenticating, because the following executes fine.
puts client.get('/me').username
Does anyone have any clues what I'm doing wrong?
I figured out that you need to include your client_id in every request.
puts client.get('/resolve', :url => 'https://soundcloud.com/random-username', client_id: 'YOUR_CLIENT_ID')