How to connect to Realm Object Server from .NET code (Xamarin)? - c#

I have a running Realm Object Server on my Mac (192.168.100.61:9080 ip), and Xamarin App on PC.
I want to save/synchronize data on the ROS.
How I can to connect to ROS from code?

You need to login/register a user and open a synchronized Realm. Something like:
// pass createUser: true to register rather than login
var credentials = Credentials.UsernamePassword("foo#bar.com", "super-secure", createUser: false);
// Login the user
var user = await User.LoginAsync(credentials, new Uri("http://192.168.100.61:9080"));
// Create a sync configuration for the Realm
// Notice the URL uses the realm scheme and not http
var config = new SyncConfiguration(user, new Uri("realm://192.168.100.61:9080/~/myrealm"));
// Finally, get the Realm instance
// This Realm will be kept in sync with the remote one
var realm = Realm.GetInstance(config);
For more details, check out the documentation.

Related

What's the route to get from a stored credential in msalcache.bin to an Azure.Core TokenCredential?

I have a number of CLI applications which use AD authorization. To simplify user login, credentials are cached in an msalcache file in a known location using code similar to this...
var storageProperties = new StorageCreationPropertiesBuilder(
".msalcache.bin", _directory)
.WithCacheChangedEvent(_config.ClientId)
.Build();
_cacheHelper = await MsalCacheHelper.CreateAsync(storageProperties);
_cacheHelper.VerifyPersistence();
Some applications also retrieve secrets from an Azure KeyVault using code similar to this
var client = new SecretClient(vault,
new ChainedTokenCredential(
new ManagedIdentityCredential(),
new AzureCliCredential()
));
Using ManagedIdentityCredential allows the code to operate from within a deployed application. AzureCliCredential is used to allow the user access from the CLI. However, as the name implies, it requires the Azure CLI module to be installed and for the user to have separately run az login.
It seems that there ought to be a way to reuse the stored credentials from the msalcache file to create a suitable TokenCredential to provide to the ChainedTokenCredential constructor. I.e. I'd like to be able to write something like...
var client = new SecretClient(vault,
new ChainedTokenCredential(
new ManagedIdentityCredential(),
new MsalCacheClient(_pathToMsalCacheFile)
));
Can anyone suggest the appropriate way to do this?

Xamarin Web Authenticator does not persist when placing app on foreground

I'm currently building a Xamarin app that uses WebAuthenticator to handle all authentication purposes. After calling AuthenticateAsync, the client is taken to an auth provider to login using their credentials. However, their system uses something called DUO, an app for different two-factor authentication methods. So when they use this it opens another app and puts the original client in the foreground. The problem arises right when the client is redirected back to the app. The access token is never passed. I also noticed this same issue when the client opens a different app. Is there a way to persist the authURI when it's put in foreground?
This is the current implementation for the call to the AuthenticateAsync
try
{
var authResult = await Device.InvokeOnMainThreadAsync(async () =>
{
var authUrl = BuildAuthUrl();
var redirect = new Uri(Redirect);
return await WebAuthenticator.AuthenticateAsync(url: BuildAuthUrl(), callbackUrl: new Uri(Redirect));
});
string code = authResult.Properties["code"];
var token = await GetToken(code);

Saving Tweetinvi credentials without re-authenticating every time

Basically what I'm trying to do is to get recent tweets from a user and do stuff with them. I'm using Tweetinvi with PIN-based authentication, as described on the website, like this:
// Create a new set of credentials for the application
var appCredentials = new TwitterCredentials("CONSUMER_KEY", "CONSUMER_SECRET");
// Go to the URL so that Twitter authenticates the user and gives him a PIN code
var url = CredentialsCreator.GetAuthorizationURL(appCredentials);
// This line is an example, on how to make the user go on the URL
Process.Start(url);
// Ask the user to enter the pin code given by Twitter
var pinCode = Console.ReadLine();
// With this pin code it is now possible to get the credentials back from Twitter
var userCredentials = CredentialsCreator.GetCredentialsFromVerifierCode(pinCode, appCredentials);
// Use the user credentials in your application
Auth.SetCredentials(userCredentials);
Now the problem is that I have to sign in and connect to Twitter every time I launch my application via browser, which is mildly annoying. I've tried to save my authentication details in a text file (Consumer Key, Consumer Secret, Access Token, Access Token Secret), and then just insert the info into appCredentials and userCredentials, but with no results, as I keep getting TwitterNullCredentialsException. So how do I save my credentials so that I don't have to reconnect on every launch?
I am the main developer of Tweetinvi.
If you store the 4 credentials information you can then reuse them with 2 different solutions :
Auth.SetUserCredentials("CONSUMER_KEY", "CONSUMER_SECRET", "ACCESS_TOKEN", "ACCESS_TOKEN_SECRET");
// OR
var creds = new TwitterCredentials("CONSUMER_KEY", "CONSUMER_SECRET", "ACCESS_TOKEN", "ACCESS_TOKEN_SECRET");
Auth.SetCredentials(creds);
The documentation might help you set up your application : https://github.com/linvi/tweetinvi/wiki/Introduction

Facebook SDK integration in WPF application

I have wpf desktop application and I want Facebook login integration in this application so that users can share images from local machine, moreover I am using "Facebook.7.0.6" sdk. Apparently I am facing following issue on login screen.
Given URL is not allowed by the Application configuration: One or more of the given URLs is not allowed by the App's settings. It must match the Website URL or Canvas URL, or the domain must be a subdomain of one of the App's domains.
And below coding I am using in my application.
private Uri GenerateLoginUrl(string appId, string extendedPermissions)
{
// for .net 3.5
// var parameters = new Dictionary<string,object>
// parameters["client_id"] = appId;
dynamic parameters = new ExpandoObject();
parameters.client_id = appId;
parameters.redirect_uri = "https://www.facebook.com/connect/login_success.html";
// The requested response: an access token (token), an authorization code (code), or both (code token).
parameters.response_type = "token";
// list of additional display modes can be found at http://developers.facebook.com/docs/reference/dialogs/#display
parameters.display = "popup";
// add the 'scope' parameter only if we have extendedPermissions.
if (!string.IsNullOrWhiteSpace(extendedPermissions))
parameters.scope = extendedPermissions;
// generate the login url
var fb = new FacebookClient();
return fb.GetLoginUrl(parameters);
}
void facebookBrowser_Navigated(Object sender,NavigationEventArgs e)
{
var fb = new FacebookClient();
FacebookOAuthResult oauthResult;
if (!fb.TryParseOAuthCallbackUrl(e.Uri, out oauthResult))
return;
if (oauthResult.IsSuccess)
LoginSucceeded(oauthResult);
}
Note : Let me know if Facebook have any change in term and condition for desktop application.
Thanks
After some study I got this link and now my application working fine.
Please set below settings on Facebook app first.
Native or desktop app? - Yes
Client OAuth login - Yes
Embedded browser OAuth Login - Yes
read more from this link :-https://www.hackviking.com/2014/11/facebook-api-login-flow-for-desktop-application/
Thanks
This error means you haven't configured well you app on facebook
If you are testing on localhost, you need to add a platform to your app, then configuring the "site url" for the example http://localhost. Then create a test app (a copy of your main app) and use it for your tests.

Testing Exchange Web Service (EWS) url

I have UI where I have the user enter the Url where I can find the Exchange Web Service(EWS). My application uses EWS to get Free/Busy information but my configuration tool just needs to set it for the user.
For now I am just asking for the host name and building up the Url from there. For example they enter example.org as the host and I build https://example.org/EWS/Exchange.asmx from that.
I would like to add a test button to ensure the host they entered is reachable by the machine they are configuring. But I'm not sure how simple or complex I need to be to test the service.
Is there any noop or bind I can do to make sure I can establish communication with EWS?
Something like:
var serviceUri = new Uri(_textBoxEwsUrl.Text));
var exchangeService = new ExchangeService();
exchangeService.Url = serviceUri;
// what can I call here to test that I can talk to the exchangeService?
exchangeService.????
Bind to the inbox folder of the users mail address. Of course, you would need his credentials to this.
Any kind of operation that results in communication with server can be used as test. Simple binding to any folder or item will throw ServiceRequestException or some different type of exception if your url or credentials are incorrect.
Sample code:
try
{
var inbox = Folder.Bind(service, WellKnownFolderName.Inbox);
}
catch(ServiceRequestException e)
{
//handle exception in some way
}

Categories

Resources