user: getMemberGroups method is not present in Graph java sdk 1.6 - azure-active-directory

I am using graph API JAVA sdk(v1.6.0) and I am trying to get all the groups that a specific user is in.
https://learn.microsoft.com/en-us/graph/api/user-getmembergroups?view=graph-rest-1.0&tabs=java#example
According to API doc, I could do something like below:
graphClient.me()
.getMemberGroups(securityEnabledOnly)
.buildRequest()
.post();
However, in java sdk 1.6.0, getMemberGroups() is not present under UserRequestBuilder.java class.
https://github.com/microsoftgraph/msgraph-sdk-java/blob/0041e58287f02036c37a8ae0a1bf30f1f616991a/src/main/java/com/microsoft/graph/requests/extensions/UserRequestBuilder.java.
Am i missing something?

I think they have replaced the getMemberOf() method with another one memberOf().
I was able to fetch all the groups for a particular user using the below code:
public static void getUserGroups(String accessToken) {
ensureGraphClient(accessToken);
String upn="test#testDomain.com";
IDirectoryObjectCollectionWithReferencesPage iDirectoryObjectCollectionWithReferencesPage = graphClient.users(upn).memberOf().buildRequest().get();
List<DirectoryObject> directoryObjects = iDirectoryObjectCollectionWithReferencesPage.getCurrentPage();
for (DirectoryObject directoryObject : directoryObjects) {
if(directoryObject.oDataType.equalsIgnoreCase("#microsoft.graph.group")) {
System.out.println(directoryObject.getRawObject().get("displayName"));
}
}
}

Related

Spring React and Sessions.. how to keep session

I have set up my spring to maintain a HTTP session on an object like so:
#Component
#SessionScope
public class Basket { .. }
controller:
#PostMapping(path="/basket/addItem/{user}", consumes = "application/json", produces = "application/json")
public Basket createBasket(#PathVariable String user, #RequestBody Item item) {
System.out.println("POSTING..................................");
return basketService.addItem(user, item);
}
now when i use a REST client, in firefox i can see that the session bean is created and maintained for the duration - multiple calls. I can append to the object. If i try another client, it gets its own session with its own bean. great..
spring logs the following:
Creation of SecureRandom instance for session ID generation using [SHA1PRNG] took [269] milliseconds.
However im trying to create a basic front end in react, when react makes a request using axios it gets a new bean every time, which means that the session must be ending after each call. IS that correct? or im not tying it to the react application...
Maybe the approach im taking is not correct, maybe i should use a a different approach, Im trying to learn about spring boot, so its a basic project... and right now i want to maintain user session for a cart. so subsequent calls i can append to the object...
by adding the following to my controller it all began to work.
#CrossOrigin(origins = { "http://localhost:3000" }, allowedHeaders = "*", allowCredentials = "true")

using the googleapis library in dart to update a calendar and display it on a webpage

I am new to dart and I have been trying to figure out how to use the googleapis library to update a calendars events, then display the calendar/events on a webpage.
So far I have this code that I was hoping would just change the #text id's text to a list of events from the selected calendars ID:
import 'dart:html';
import 'package:googleapis/calendar/v3.dart';
import 'package:googleapis_auth/auth_io.dart';
final _credentials = new ServiceAccountCredentials.fromJson(r'''
{
"private_key_id": "myprivatekeyid",
"private_key": "myprivatekey",
"client_email": "myclientemail",
"client_id": "myclientid",
"type": "service_account"
}
''');
const _SCOPES = const [CalendarApi.CalendarScope];
void main() {
clientViaServiceAccount(_credentials, _SCOPES).then((http_client) {
var calendar = new CalendarApi(http_client);
String adminPanelCalendarId = 'mycalendarID';
var event = calendar.events;
var events = event.list(adminPanelCalendarId);
events.then((showEvents) {
querySelector("#text2").text = showEvents.toString();
});
});
}
But nothing displays on the webpage. I think I am misunderstanding how to use client-side and server-side code in dart... Do I break up the file into multiple files? How would I go about updating a calendar and displaying it on a web page with dart?
I'm familiar with the browser package, but this is the first time I have written anything with server-side libraries(googleapis uses dart:io so I assume it's server-side? I cannot run the code in dartium).
If anybody could point me in the right direction, or provide an example as to how this could be accomplished, I would really appreciate it!
What you might be looking for is the hybrid flow. This produces two items
access credentials (for client side API access)
authorization code (for server side API access using the user credentials)
From the documentation:
Use case: A web application might want to get consent for accessing data on behalf of a user. The client part is a dynamic webapp which wants to open a popup which asks the user for consent. The webapp might want to use the credentials to make API calls, but the server may want to have offline access to user data as well.
The page Google+ Sign-In for server-side apps describes how this flow works.
Using the following code you can display the events of a calendar associated with the logged account. In this example i used createImplicitBrowserFlow ( see the documentation at https://pub.dartlang.org/packages/googleapis_auth ) with id and key from Google Cloud Console Project.
import 'dart:html';
import 'package:googleapis/calendar/v3.dart';
import 'package:googleapis_auth/auth_browser.dart' as auth;
var id = new auth.ClientId("<yourID>", "<yourKey>");
var scopes = [CalendarApi.CalendarScope];
void main() {
auth.createImplicitBrowserFlow(id, scopes).then((auth.BrowserOAuth2Flow flow) {
flow.clientViaUserConsent().then((auth.AuthClient client) {
var calendar = new CalendarApi(client);
String adminPanelCalendarId = 'primary';
var event = calendar.events;
var events = event.list(adminPanelCalendarId);
events.then((showEvents) {
showEvents.items.forEach((Event ev) { print(ev.summary); });
querySelector("#text2").text = showEvents.toString();
});
client.close();
flow.close();
});
});
}

Google Cloud Endpoints: Return type of api method

In google cloud endpoints api class, I have following error while generating client endpoint library for android client:
java.lang.IllegalArgumentException: Type class java.lang.Boolean cannot be used as a return type
I have tried with other generic types as well, I guess api method can't return any generic object. I can't figure it out why this is not allowed in api method?
Is there any hack of this limitation?
/**
* Returning error during client endpoint generation.
*/
#ApiMethod(name = "isValidEntity")
public Boolean isValidEntity(BusinessAccount businessAccount) {
EntityManager mgr = getEntityManager();
Boolean isValid = false;
try{
.....
....
} finally {
mgr.close();
}
return isValid;
}
PS: I couldn't find enough documentation on api annotations other than Getting Started: cloud endpoint google documentation. I will appreciate if someone can point me to relevant sources.
GPE docs say, "In the Endpoint methods, the return value type cannot be simple type such as String or int. The return value needs to be a POJO, an array or a Collection."
https://developers.google.com/eclipse/docs/endpoints-addentities

RPC call to external server

I am a new bie on GWT, I wrote an application on abc.com, I have another application i.e. xyz.com, xyz.com?id=1 provides me a data in json format, I was thinking to find a way that how to get that json file in abc.com via RPC call, because I have seen tutorials in which RPC calls are used to get data from its server. any help will be appreciated.
EDIT
I am trying to implement this in this StockWatcher tutorial
I changed my code slightly change to this
private static final String JSON_URL = "http://localhost/stockPrices.php?q=";
AND
private void refreshWatchList() {
if (stocks.size() == 0) {
return;
}
String url = JSON_URL;
// Append watch list stock symbols to query URL.
Iterator iter = stocks.iterator();
while (iter.hasNext()) {
url += iter.next();
if (iter.hasNext()) {
url += "+";
}
}
url = URL.encode(url);
MyJSONUtility.makeJSONRequest(url, new JSONHandler() {
#Override
public void handleJSON(JavaScriptObject obj) {
if (obj == null) {
displayError("Couldn't retrieve JSON");
return;
}
updateTable(asArrayOfStockData(obj));
}
});
}
before when I was requesting my url via RequestBuilder it was giving me an exception Couldn't retrieve JSON but now JSON is fetched and status code is 200 as I saw that in firebug but it is not updating on table. Kindly help me regarding this.
First, you need to understand the Same Origin Policy which explains how browsers implement a security model where JavaScript code running on a web page may not interact with any resource not originating from the same web site.
While GWT's HTTP client and RPC call can only fetch data from the same site where your application was loaded, you can get data from another server if it returns json in the right format. You must be interacting with a JSON service that can invoke user defined callback functions with the JSON data as argument.
Second, see How to Fetch JSON DATA

tweetsharp implementation in mvc.net

Hi
I want to use Tweetsharp in my mvc.net application to get the list offriends and to share image with them.
But i haven't got the proper documentation and sample for the same. What is need to add in controller action and what in view page.
Please give some links for the same.
Thanks
munish
public void MyMethod() {
TwitterService service = new TwitterService(key, secret, "Token", "Secret");
ListFriendsOptions options = new ListFriendsOptions();
options.Cursor = 12345;
// should the response have user entities
options.IncludeUserEntities = false;
// The screen name of the user for whom to return results for.
options.ScreenName = "";
options.SkipStatus = false;
// The ID of the user for whom to return results for.
options.UserId = 12345;
// this will return a list of friends for the specified user.
TwitterCursorList<TwitterUser> listOfFriends = service.ListFriends(options);
}
Also note the code above uses a third party library called TweetSharp.
As for the images im not sure as to what to do but you can look at the twitter REST API v1.1 for information
https://dev.twitter.com/docs/api/1.1/get/friends/list
https://dev.twitter.com/docs/api/1.1
TweetSharp
https://github.com/danielcrenna/tweetsharp
I don't know about Tweetsharp but take a look at linq2twitter. It provides easy access to the Twitter API through the use of LINQ.

Resources