I have the following asciidoc where I would like to have multiple section titles.
= REST API
== Token
Tokens are used for making authenticated requests to the API.
=== Getting a token
This is how you get a token
But it ends up looking something like this, the second section title (Token) isnt working.
The solution was to insert line breaks between each section
= REST API
== Token
Tokens are used for making authenticated requests to the API.
=== Getting a token
This is how you get a token
Related
In my ASP.NET Core Web Api, I'm trying to call Graph API to retrieve the data of other users in the organization. I'm using the On Behalf Of flow. The bootstrap token is passed in from SPA client code.
In the Startup code, I have:
builder.Services
.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
.AddMicrosoftIdentityWebApi(builder.Configuration)
.EnableTokenAcquisitionToCallDownstreamApi()
.AddMicrosoftGraph("https://graph.microsoft.com/beta", "user.read user.readbasic.all profile")
.AddInMemoryTokenCaches();
In the Controller's Action, I have:
_graphServiceClient.Users.Request()
.Filter($"mail eq 'someuser#myorg.com'")
.Select((user) => new {
DisplayName = user.DisplayName,
City = user.City,
Country = user.Country,
BusinessPhones = user.BusinessPhones
})
.Request()
.GetAsync();
However, at runtime, I only get the DisplayName value. I don't get the values of City, Country or BusinessPhones. They are al null.
When I tried the same query in Graph Explorer, I saw the values for all of them.
What am I missing?
First, your code snippet has an error that you wrote 2 .Request(), you should remove one.
Whatever flow you used are all generating an access token so that you can access the api, therefore when you got correct data from the api, that means you have a right setting in using the flow, so I think if there's any issue, it should locate at the part of calling api. Then I did some test in my side.
Could you pls check if you call the api directly, you can get the value of City, Country and BUsinessPhones these 3 properties? Per my test, when I call the api, I can get response like screenshot below and by default it's null
https://graph.microsoft.com/beta/users?$filter=mail eq
'tinywang#xxx.onmicrosoft.com'&$select=mail,city,country,DisplayName,BusinessPhones,userType,usageLocation
And when I followed this tutorial to call the api via sdk, I got the same result:
My idea is checking the response of calling the api first and if we can't find the issue, then could you pls provide the tutorial you followed to help reproduce the issue.
I need to do CRUD on Custom Search Engines. From documentation, it looks pretty straight forward. I keep getting 401 responses though.
I am using Google.Apis.Oauth2.v2 to get a token:
String serviceAccountEmail = "blahblahblah#developer.gserviceaccount.com";
var certificate = new X509Certificate2(#"key.p12", "blah", X509KeyStorageFlags.Exportable);
var credential = new ServiceAccountCredential(
new ServiceAccountCredential.Initializer(serviceAccountEmail)
{
Scopes = new[] { "https://www.googleapis.com/auth/cse" }
}.FromCertificate(certificate));
bool result = credential.RequestAccessTokenAsync(CancellationToken.None).Result;
TokenResponse token = credential.Token;
I then add the token to the following request (Authorization: Bearer mytoken):
GET http://cse.google.com/api/<USER_ID>/cse/<CSE_ID>
There are a few things that jump at me.
Exact quote from documentation:
Although you can set HTTP requests to the URL http://cse.google.com/api/[USER_ID]/cse/[CSE_ID], we recommend using
the following URL instead:
http://cse.google.com/api/[USER_ID]/cse/[CSE_ID]
Note that both URL's are exactly the same.
In authentication section, the sample is using ClientLogin, which is deprecated. No samples with OAuth 2.0.
In the document's example, it says:
Each Custom Search engine is identified by a unique ID created by
combining a user ID with a Custom Search engine ID, separated by a
colon, like this:
011737558837375720776:mbfrjmyam1g In this case, the user ID is
011737558837375720776, and the search engine ID is mbfrjmyam.
You would have noticed that the search engine ID is 2 characters short of what it looks like should be.
Nowhere I have seen the scope as "https://www.googleapis.com/auth/cse". I just copied it from a stackoverflow post.
I understand this is a very long question, but I hope this will help the next person to look at this and consider these points.
Anyone knows why the 401s?
I have implemented Token Authentication with django rest framework and I can post username and password to /api-token-auth/ and get the token.
url(r'^api-token-auth/', token_views.obtain_auth_token)
In addition to the token, I want to get the User object related to the returned token.
How can I override/add to this view and also return the actual User object?
You can find the relevant view here:
https://github.com/tomchristie/django-rest-framework/blob/master/rest_framework/authtoken/views.py#L21
Assuming you've created some sort of User serializer already, you can basically take the user instance there and shove it into your UserSerializer. then add it to the response, something like the below.
...
user_serializer = UserSerializer(user)
return Response({'token': token.key, 'user': user_serializer.data})
I'm basically querying the google places API for stores in atlanta.
https://maps.googleapis.com/maps/api/place/search/json?location=33.7488,-84.3874&radius=50000&sensor=false&key=YOUR_KEY_HERE&types=amusement_park|art_gallery|bakery|bar|beauty_salon|bicycle_store|book_store|bowling_alley|cafe|car_repair|car_wash|clothing_store|florist|furniture_store|gym|hair_care|home_goods_store|jewelry_store|laundry|liquor_store|museum|night_club|pet_store|pharmacy|restaurant|shoe_store|spa|store|veterinary_care|zoo
This as expected returns a result with a page token to get another page of data with the same query.
https://maps.googleapis.com/maps/api/place/search/json?key=YOUR_KEY_HERE&page_token=PAGE_TOKEN_HERE
According to their API this second URL is all I need to get the 2nd page of data. But it ALWAYS returns "REQUEST_DENIED".
"{\n \"html_attributions\" : [],\n \"results\" : [],\n \"status\" : \"REQUEST_DENIED\"\n}\n"
It's not clear WHY I'm getting request denied. I'm nowhere NEAR my daily limit. If I try to run the 2nd URL with ALL the given parameters from the first URL with the Token Included it acts as if I'm requesting the 1st page all over again and ignores the page_token entirely.
Has anybody gotten this page_token to work?!?!?!?!?!
This is a bug in the documentation and will be fixed asap. The correct parameter to use is pagetoken NOT page_token.
I'm basically querying the google places API for stores in atlanta.
https://maps.googleapis.com/maps/api/place/search/json?location=33.7488,-84.3874&radius=50000&sensor=false&key=YOUR_KEY_HERE&types=amusement_park|art_gallery|bakery|bar|beauty_salon|bicycle_store|book_store|bowling_alley|cafe|car_repair|car_wash|clothing_store|florist|furniture_store|gym|hair_care|home_goods_store|jewelry_store|laundry|liquor_store|museum|night_club|pet_store|pharmacy|restaurant|shoe_store|spa|store|veterinary_care|zoo
This as expected returns a result with a page token to get another page of data with the same query.
https://maps.googleapis.com/maps/api/place/search/json?key=YOUR_KEY_HERE&page_token=PAGE_TOKEN_HERE
According to their API this second URL is all I need to get the 2nd page of data. But it ALWAYS returns "REQUEST_DENIED".
"{\n \"html_attributions\" : [],\n \"results\" : [],\n \"status\" : \"REQUEST_DENIED\"\n}\n"
It's not clear WHY I'm getting request denied. I'm nowhere NEAR my daily limit. If I try to run the 2nd URL with ALL the given parameters from the first URL with the Token Included it acts as if I'm requesting the 1st page all over again and ignores the page_token entirely.
Has anybody gotten this page_token to work?!?!?!?!?!
This is a bug in the documentation and will be fixed asap. The correct parameter to use is pagetoken NOT page_token.