Unable to find /oauth/device/code Auth0 Java API - java

Is there an API to fetch the device code via Auth0 Java API, we use the following snippet in Go, the question is if there is a standard API or should we make a HTTP request call
url := "https://dev-foo.us.auth0.com/oauth/device/code"
payload := strings.NewReader("client_id=RO6N7mr&scope=openid&audience=https://dev-foo.us.auth0.com/api/v2/")
req, _ := http.NewRequest("POST", url, payload)

The documentation tells you that you need to send a POST request like the following:
POST https://YOUR_DOMAIN/oauth/device/code
Content-Type:
application/x-www-form-urlencoded
client_id=YOUR_CLIENT_ID&scope=SCOPE&audience=API_IDENTIFIER
and the response would look like
HTTP/1.1 200 OK
Content-Type: application/json
{
"device_code":"GmRh...k9eS",
"user_code":"WDJB-MJHT",
"verification_uri":"https://YOUR_DOMAIN/device",
"verification_uri_complete":"https://YOUR_DOMAIN/device?user_code=WDJB-MJHT",
"expires_in":900, //in seconds
"interval":5
}

Related

How to access json data which is present in payload of angular request in springBoot post API || syncfusion angular calender

Getting the below data in the payload tab of my browser while sending post requests.
"--batch_8c82e185-cbdf-4d70-a62d-a48c9e869bf8
Content-Type: application/http; msgtype=request
POST /api/null HTTP/1.1
Content-Type: application/json; charset=utf-8
Host: localhost:4200
{"Subject":"ankita","StartTime":"2021-11-29T04:00:00.000Z","EndTime":"2021-11-29T04:30:00.000Z","IsAllDay":false,"StartTimezone":null,"EndTimezone":null,"RecurrenceRule":null,"Id":4}
--batch_8c82e185-cbdf-4d70-a62d-a48c9e869bf8--"
Note: I am using a third-party library(syncfusion calendar) where I can't customize my request in the body part with JSON.
I am only concerned with the above JSON data.
I want to access this data in the post API method(addAppointment) in spring boot.
consider the below code for the controller:
#RequestMapping(value = "/appointment/{batch}" , method = RequestMethod.POST)
public ResponseEntity<?> addAppointment(#PathVariable Map batch,HttpServletRequest request) throws IOException {
/* code required to access that payload JSON data*/
}
what line of code is required to access that JSON data?
Please help.

HTTP Response 401 while trying to subscribe Outlook Events - Java

I am using Outlook Rest API to subscribe events. However, I get error code 401 although I include the access token. I get the access token following https://learn.microsoft.com/en-us/outlook/rest/java-tutorial this tutorial. And my payload is like the following:
{
"#odata.type":"#Microsoft.OutlookServices.PushSubscription",
"Resource":"https://outlook.office.com/api/v2.0/me/events",
"NotificationURL":URL,
"ChangeType":"Created"
}
with the header:
authorization: Bearer + access token which I get from the tutorial. (I.E EwBAA8l6BAAURSN/FHlDW5xN74t6GzbtsBBeBUYAAeybQmu+RnQcYAQ3wTW3kJUclA03jKgc4Sdx2mp5SOlLswSAr9zTmO7qk33wpTD3ULZkUrl9IpTnnhtjeoSXt+z5GRRtmL40jyvAghrTseO8yEZtR04SLjl6i1KZNXxZwUTK8s6DkXESwkwaTmQKPckKHi9XeIbx8dolnT7vEeeUo5rmzcG251dQokfZYHCar3bd1bysV7oaTt5Iis6qgkYtg4BL/32QObgI8SHQS4my7FSsqLYFchYExEFeBXgUjt4yE0G0bbmykz3T5C713DAqo8BtCkkbRIckv6N4bpq84bpzaDAgdgHhnpcYzUaViJ2zhZXMrShUdpddug+DPkEDZgAACILe9sz+3mX7EAJrVvnkVpyZzC9WvQkY4xET3KdEstT..... Something like this)
content-type: application/json
Why do I get 401?
Thank you.
A 401 means that your token isn't valid for what you're trying to do. It could be expired, invalid, etc. Typically the body of the response gives more detail on the reason of the 401.
I'd recommend going to https://oauthplay.azurewebsites.net/ and playing with the notifications API there to see how it all works.

OData POST Response

I am giving request to OData POST in Json format and it's returning the same request to me.
POST URL= http://localhost:8085/MagicXpiOData/Odata_get.OData_1/Student_details
Body:
{"Division": "Nashik"}
Content-Type = application/json
Response:
{
"#odata.context": "$metadata#Student_details",
"Division": "Nashik"
}
Is this a correct response?
I think it should return a status code for success or not.
What you show above is the response body, which usually contains the OData.Context. Beside that you should find the HTTP Status Code in the header, which might be something like
HTTP/1.1 200 OK
HTTP/1.1 201 Created
and when you create a new entry also a location header.
Some examples that show typical requests and responses can be found in this Basic Tutorial
So generally your response looks ok. Maybe you can add the response header in your question, then we can see if everything is there what should be there.
When you send your request with a tool like Postman or Fiddler, you might by default only see the response body. To see the headers you need to switch to Headers, or Raw in Fiddler to see the full response (header and body).

Dynamics CRM 2016.Web API Auth. I have token, now what?

Using ADAL libs for java I managed to get Access,Refresh and ID Tokens using my office365 credentials.
Now my intention is using REST Web APIs, my intention is to create an entity, as a proof of concept. Based on my experience with other venders and REST APIs, once you have a valid token, you just add it as a Authorization header like:
Authorization=Bearer 709709JHKLJHKJLhHKHKJHKH...etc
Is something similar to this in Dynamic CRM 2016?
Here here is nice info about composing a POST http request, but I am missing the Authorization part... Any idea guys?
Here is a valid GET request to pull back accounts.
GET https://<CRM DOMAIN>.com/api/data/v8.1/accounts HTTP/1.1
Authorization: Bearer:<TOKEN GOES HERE>
Host: <CRM DOMAIN>.com
And here is a valid POST
POST https://<CRM DOMAIN>.com/api/data/v8.1/accounts HTTP/1.1
Content-Type: application/json; charset=utf-8
Accept: application/json
Authorization: Bearer:<TOKEN GOES HERE>
Host: <CRM DOMAIN>.com
Content-Length: 224
{
"name": "Sample Account",
"creditonhold": false,
"address1_latitude": 47.639583,
"description": "This is the description of the sample account",
"revenue": 5000000,
"accountcategorycode": 1
}

Get username and password from HttpServletRequest

I need to get username and password from HttpServletRequest to process the basic authentication. What I have is CXF endpoint and the basic auth interceptor. The HttpServletRequest I get like this:
public void handleMessage(Message message)
throws Fault {
HttpServletRequest request = (HttpServletRequest) message.get(AbstractHTTPDestination.HTTP_REQUEST);
}
When I tried to debug the code and I see that:
request.getAuthType() is null
request.getRemoteUser() is null
The username and password I am sending with the request from Soap UI. So the question is how am I able to get the username and password from the request?
EDIT
Header looks like this:
POST http://localhost:8011/GradIrelandUserRegistration HTTP/1.1
Accept-Encoding: gzip,deflate
Content-Type: text/xml;charset=UTF-8
SOAPAction: ""
Authorization: Basic UGF1bGl1czpQYXVsaXVzMTIz
Content-Length: 3170
Host: localhost:8011
Connection: Keep-Alive
User-Agent: Apache-HttpClient/4.1.1 (java 1.5)
They say that Authorization is basic, but then why call request.getAuthType() is returning null?
I was able to figure it out my self. In Soap UI I needed to change the Authentication type to:
Preemptive
and then use:
AuthorizationPolicy policy = (AuthorizationPolicy) message.get(AuthorizationPolicy.class.getName());
From the policy object now I am able to get the username and password.
This may be helpful to you
.
I'm bit new in SOAP data parsing so, if not working then let me know brief problem.
.
Also Check this J-Query Plugin for parsing SOAP services with the database. check this Stack Overflow

Categories

Resources