How other users will connect to my dropbox application? - vb.net

Scenario: I want to create a vb.net application which will automatically upload a backup file to my clients' dropbox account. So each of my client will be able to use my app and upload the backup file o their own dropbox account.
Steps I already did:
I have created an application on Dropbox in App Console area.
I have edited the permissions which my app will need.
I have generated my access token from my app Panel (lest name it dx)
Using visual studio (and vb.net language) I created the code below(Imports Dropbox.Api, System.IO are needed)
Public Class Form1
Public dbx = New DropboxClient("myAccessToken")
'~~~~~~~~~~~~~~~Upload File Button
Private Sub btnUploadFile_Click(sender As Object, e As EventArgs) Handles btnUploadFile.Click
Dim task = System.Threading.Tasks.Task.Run(CType(AddressOf UploadFile, Func(Of Task)))
task.Wait()
End Sub
'~~~~~~~~Code to upload the file on dropbox account
Public Async Function UploadFile() As Task
Await dbx.Files.UploadAsync(DropboxPath & FileName, body:=(New FileStream(LocalPath & FileName, FileMode.Open, FileAccess.Read)))
End Function
End Class
Until here everything work great! (and i can successfully upload a file to my dropbox)
But now, I am confused about how my app users will work with my application and for the further steps.
I know that I have to "Apply my App for Production", but after what?
I have read many articles but still confused about the way.
Is there any simple way to help me?

While you can use a generated access token to test against your own Dropbox account, in order to have arbitrary end-users connect their accounts to your app, you'll need to implement the OAuth app authorization flow. You can find more information in the OAuth Guide and authorization documentation.
For the official Dropbox API v2 .NET SDK, you can find examples of using the OAuth flow in the OauthBasic example (non-PKCE, meant for server-side apps) as well as in the OAuthPKCE example (PKCE, meant for client-side apps).

Related

VB.NET console application - login to website and download file

I am working an a VB.NET console application which automatically downloads textfiles from different websites. So far I've been using
My.Computer.Network.DownloadFile(url, local_path, username, password)
and it works fine - but there is one website which uses cookies. Under normal circumstances I have to manually visit the website in my browser, login by entering my credentials into a login form, press the "Log in" button and then there is a link which lets me download the file.
If I use this link in my normal download function, I always receive a message "Not logged in." so this is basically my problem:
I need to call this URL with a WebClient or HttpWebRequest and log in using my credentials before I tell it to download the file.
However, I can not find a good example or guideline anywhere for this problem.
So far, I've tried the following:
Dim client As New WebClient
Dim values As New NameValueCollection()
values.Add("login[username]", "<my_login>")
values.Add("login[password]", "<my_password>")
client.UploadValues("https://www.website.com/customer/account/login/", values)
Dim strDL As String = client.DownloadString("https://www.website.com/downloadFile.php/")
Console.WriteLine(strDL)
This isn't working and my console just puts out "Not logged in."
I know that you can also work with a CookieContainer but not with WebClient, only with HttpWebRequest. I guess I didn't grasp the concept of that yet. In my case, the cookies for the website expire after 1 hour so I assume that my approach with the NameValueCollection also would not work (or maybe it would but only as long as the cookie is valid) so my guess is that I have to somehow log into the website, get the cookie names and values and then use those information to download the file. However, as I said, I can not find a good example on how to do this anywhere.

Upload file to Microsoft OneDrive using graph SDK using asp.net core

I am trying to upload a file to OneDrive using Graph SDK for .Net Core from worker service.
Basically, some files are created at random time and those files needs to be uploaded to specified path on OneDrive from worker service at midnight every day.
I have following information stored in appconfig.json file in application:
ClientID
ClientSecret
TenantID
I have checked samples on various sites but could not find how to upload files using above ID and Secret. I believe there must but some kind of authProvider that I could initialize using above ID and Secret.
I also checked miscrosoft's documentation but coudl not find any example on how to upload file using SDK with ID and Secret.
https://learn.microsoft.com/en-us/onedrive/developer/rest-api/api/driveitem_put_content?view=odsp-graph-online
Additional Point
Upload new file
Overwrite if file already exists(hope that graph already supports this)
file size is < 4MB
path format /folder1/folder2/filename.pdf
Any help would be appreciated.
Remember to assign Application permission (Client credentials flow) to the app registration. See Application permission to Microsoft Graph.
You can use Client credentials provider.
IConfidentialClientApplication confidentialClientApplication = ConfidentialClientApplicationBuilder
.Create(clientId)
.WithTenantId(tenantID)
.WithClientSecret(clientSecret)
.Build();
ClientCredentialProvider authProvider = new ClientCredentialProvider(confidentialClientApplication);
Upload small file (<4M):
GraphServiceClient graphClient = new GraphServiceClient(authProvider);
using var stream = new System.IO.MemoryStream(Encoding.UTF8.GetBytes("The contents of the file goes here."));
await graphClient.Users[{upn or userID}].Drive.Items["{item-id}"].Content
.Request()
.PutAsync<DriveItem>(stream);
If you want to upload large file, see Upload large files with an upload session.
UPDATE:
Use Install-Package Microsoft.Graph.Auth -IncludePrerelease in Tools -> NuGet Package Manager -> Package Manager Console.
It supports both uploading a new file and replacing an existing item.
For how to get the items id, please refer to Get a file or folder.
For example, get the item id of /folder1/folder2 (have a quick test in Microsoft Graph Explorer):
GET https://graph.microsoft.com/v1.0/users/{userID}/drive/root:/folder1:/children
It will list all the children in folder1, including folder2. Then you can find item id of folder2.
UPDATE 2:
Client credentials provider is application identity while all the providers below are user identity.
Since you want to access personal OneDrive (including user identity), you could choose Authorization code provider or Interactive provider.
Authorization code provider: you need to implement interactively sign-in for your web app and use this provider.
Interactive provider: you can easily use this provider to implement interactively sign-in in a console app.
You can have a quick test with the second provider.
Please note that you should add the Delegated (personal Microsoft account) permissions into the app registration. See Delegated permission to Microsoft Graph.
And in this case, you should modify all graphClient.Users[{upn or userID}] to graphClient.Me in your code.
I'm afraid that you have to implement sign-in interactively auth flow to access personal OneDrive.

Pass Logic App credential to custom SharePoint Client C# Function App SharePoint

I have created logic apps in Azure that uses my credential to connect to our SharePoint Online sites and then run without me being around. I want to perform more complex operations on the SharePoint sites and would prefer to create a C# Function App. However I cannot see a way to pass my credentials to the Microsoft.SharePoint.Client without my having to be there to authenticate. I have researched using a certificate but that requires admin approval which I cannot get. Is there a way for me to use the existing SharePoint Logic App connection, which has my credential information, and pass that to a custom Function App? Here's a quick image of how the connection looks in the Logic App. Instead of using the built in Azure action, I want to replace it with my custom Function App passing that connection to the function app.
Then I would need use that to somehow create the ClientContext:
var ctx = new ClientContext(siteUrl);
ctx.ExecutingWebRequest += (s, e) =>
{
e.WebRequestExecutor.RequestHeaders["Authorization"] = "Bearer " + authenticationResult.AccessToken;
};
return ctx;
Which could then be used against the SharePoint site:
using (ClientContext ctx = await csomHelper.GetClientContext(siteUrl))
{
Web web = ctx.Web;
ctx.Load(web);
ctx.ExecuteQuery();
log.LogInformation($"found site : {web.Title}");
}
While I believe there is no way to fetch the access token from an existing connection, you could expose your function app as a custom connector for use in logic apps.
Firstly, you would need an Azure AD app registration with appropriate permissions to sharepoint.
Then, while creating the custom connector, the security config should be Generic OAuth 2.0 with appropriate details of the Azure AD you created earlier.
And you can then use the custom connector in your logic app, which will trigger an OAuth flow similar to other connectors.
There is an official doc for creating a custom connector for an Azure AD protected Azure Function which is pretty similar and something that you can refer.

Generate Proxy VB Class from WSDL for Windows Phone 8.1

I just finished working on the Android port of the iOS App that I have and now the client also wants to have a Windows Phone version just so they can have an App for all three markets and right now I'm not sure how to consume the Web Services as the "Add Service Reference" option has been removed for Windows Phone 8.1 apps. I don't know if there's any online alternatives that create a proxy class like what the "Add Service Reference" did, I tried using the Svcutil.exe option to generate my own proxy but when I imported the file it was littered with errors and undefined types that aren't available for Windows Phone projects. Other than the proxy route I was reading that HttpClient should work, but so far I haven't been able to have much success with it (below is what I tried but I keep getting an error, and this is a more simple service, where some of the other services are more complex). For the Android and iOS projects I was able to find some online generators that created the proxy classes from the WSDL files and I've been trying to see if there's something similar for WP8.1 but so far I've been unsuccessful.
Public Shared Async Function GetSession() As Task
Dim values As New List(Of KeyValuePair(Of String, String)) From {
New KeyValuePair(Of String, String)("RepLogin", "username"),
New KeyValuePair(Of String, String)("RepPass", "password")}
Dim httpClient As New HttpClient(New HttpClientHandler())
Dim requestString As String = mobileAddress + "?op=VerifyRep"
Dim response As HttpResponseMessage = Await httpClient.PostAsync(requestString, New FormUrlEncodedContent(values))
Debug.WriteLine(response)
Dim responseString = Await response.Content.ReadAsStringAsync()
Debug.WriteLine("response string contains: " + responseString)
End Function
And before anyone suggests that the Web Service should be updated from SOAP to a WCF or something else that really isn't a solution in this scenario since the client already has several Web Applications and now two mobile apps (the iOS and Android ones) that all use this Service without any issues and it's going to be hard to convince them that everything needs to be reworked just for the sake of getting a Windows Phone app up and running
Okay, so I figured out my problem was that when I created the project I just chose the Windows Phone template, which uses the Windows Runtime in order to share code with a Windows 8.1 App as well (which I still don't know how they would share if you can't consume a web service but that's not for here). I created a new project using the Windows Phone Silverlight template and now I can add a Service Reference as normal, and since I'm not planning on creating a Windows App that will share code with the Windows Phone app this is the way to go. Thanks anyways.

Problems working with Google Calendar Api V3 and PHP

I'm just trying to make a little, simple application (that i already made two years ago in Objective-C with api V1) that presents a screen with time of event and description and a button : "insert event in your calendar".
Every user has, obviously, to configure the application with his google username and password.
The app simplifies some process using the first calendar available.
I had infinite problem trying to do it with javascript (this app will be made in html5), so, looking at docs, I ended up trying to make a back-end on my server in php5 (thought it could be easier...ohohoho).
So, i read docs from here : https://developers.google.com/google-apps/calendar/
What i did :
1)
Get to the Google Developers Console.
Created a project.
I now have this (not real keys):
OAuth 2.0
Client ID 352xxxyy9.apps.googleusercontent.com
Email address 3527xxxy#developer.gserviceaccount.com
Service Account
Client ID 3523xxxyy419-vpfgdfg9u77s0.apps.googleusercontent.com
Email address 35ssss9-zzzzsnhavna78ea0b9gvn6a9u77s0#developer.gserviceaccount.com
Public key fingerprints :ac15ddfxdffrtg5565fgfg545r
2)
I installed Google APIs Client Library for PHP (beta) in my server.
doc says:
Using the Google APIs Client Library for PHP requires that you download the PHP source. In the future, packages will be provided. Refer to the project page for more details.
Run the following commands to download and install the source: svn blaj blah blah.
I copied the entire source in my server. Easy :)
Then..
3) You can now import the classes you will need using the following statements:
require_once "../src/apiClient.php";
require_once "../src/contrib/apiCalendarService.php";
Ok, i'll insert them in my php script !
4)" Configure your app"
You must instantiate a client to make requests to the API. All requests to the Google Calendar API require authorization.
The following code demonstrates how to configure an authorized service object using OAuth 2.0 for native applications. For more information, see Authorize Requests.
To find your project's client ID and client secret, do the following:
Go to the Google Developers Console.
Select a project.
In the sidebar on the left, select APIs & auth. In the displayed list of APIs, make sure the Google Calendar API status is set to ON.
In the sidebar on the left, select Credentials.
Find the lines labeled Client ID and Client secret. Note that there may be a client ID without a client secret, for use with Compute Engine and App Engine; in that case, create a new client ID and client secret by selecting Create New Client ID.
Edit the src/config.php file to put in your developer API information.
global $apiConfig;
$apiConfig = array(
// Site name to show in Google's OAuth authentication screen
'site_name' => 'www.example.org',
// OAuth2 Setting, you can get these keys in Google Developers Console
'oauth2_client_id' => 'YOUR_CLIENT_ID',
'oauth2_client_secret' => 'YOUR_CLIENT_SECRET',
'oauth2_redirect_uri' => 'YOUR_REDIRECT_URL',
// The developer key; you get this from Google Developers Console
'developer_key' => 'YOUR_DEVELOPER_KEY',
...
// Which Authentication, Storage and HTTP IO classes to use.
'authClass' => 'apiOAuth2',
....
// Definition of service specific values like scopes, OAuth token URLs, etc
'services' => array(
'calendar' => array('scope' => 'https://www.googleapis.com/auth/calendar'),
)
);
But they are DIFFERENT from the key i have, what's wrong ????
What are client secrets ? redirect_url??
Please help.
I think you need to setup a service account access as described here:
https://code.google.com/p/google-api-php-client/wiki/OAuth2#Service_Accounts
I had difficulties to get it work as I made many trial and errors and my cache got filled with non-working token.
If ever you find yourself not able to access the calendar even after following all the steps, try to change this line of code:
$client->setAssertionCredentials(new Google_AssertionCredentials(SERVICE_ACCOUNT_NAME, array('https://www.googleapis.com/auth/prediction'),$key));
to this:
$client->setAssertionCredentials(new Google_AssertionCredentials(SERVICE_ACCOUNT_NAME, array('https://www.googleapis.com/auth/prediction'),$key, 'notasecret','http://oauth.net/grant_type/jwt/1.0/bearer',false,false));
The last false tells AssertionCredential class to not use any cache. I did it once and then it worked with it set to true afterward.
First go here https://console.developers.google.com/project that is where you configure your app...
Click on your project, then on the left side you will see APIs & Auth, click on Credentials. You will need to create your OAuth, and Public API Access keys.
Once you have done that you will then enter those into the appropriate client_id, secret, redirect etc.
The redirect uri is the same page your app is on, its the page the user gets sent back to after authorizing.
I had the same problem.
On this page, when you click on the Create new Client Id, choose Web application and it shoudl give you the client secret key as well.
https://console.developers.google.com/project
Add a project etc.
Hope it helps