In Back4App project, Can multiple apps (different platforms) can access same database and authentication? - database

I wanted to use back4app as my backend to my mobile apps & web app/site. My question is can I access same db and authentication in single project (shared plan). If yes show me some reference to get. Thank you. (Try to understand my English).

Yes, you can use the same database for your mobile apps and website, you only need to use the same app credentials in your initialization code.
Let me better explain it:
For Android apps, you must use:
Parse.initialize(new Parse.Configuration.Builder(this)
.applicationId("APP-ID-HERE")
// if defined
.clientKey("CLIENT-KEY-HERE")
.server("https://parseapi.back4app.com")
.build()
);
For iOS (swift):
let configuration = ParseClientConfiguration {
$0.applicationId = "PASTE_YOUR_APPLICATION_ID_HERE"
$0.clientKey = "PASTE_YOUR_CLIENT_ID_HERE"
$0.server = "https://parseapi.back4app.com"
}
Parse.initialize(with: configuration)
For iOS (obj-C):
[Parse initializeWithConfiguration:[ParseClientConfiguration configurationWithBlock:^(id<ParseMutableClientConfiguration> configuration) {
configuration.applicationId = #"PASTE_YOUR_APPLICATION_ID_HERE";
configuration.clientKey = #"PASTE_YOUR_CLIENT_ID_HERE";
configuration.server = #"https://parseapi.back4app.com/";
}]];
And for the website (JS):
Parse.initialize("YOUR_APP_ID", "YOUR_JS_KEY"); //PASTE HERE YOUR Back4App APPLICATION ID AND YOUR JavaScript KEY
Parse.serverURL = "https://parseapi.back4app.com/";
If you use the credentials (App ID, Client Key / Javascript Key) of the same app, you'll connect all your "different" projects to the same database.
In addition, you can get these credentials following this guide: https://help.back4app.com/hc/en-us/articles/115000754772-Where-are-my-Keys-and-ID-

Related

Why is GoogleAuth failing to refresh in my webapp?

I am testing using PyDrive in my web app and the refresh part causes it to return a 500 error. Sometimes it works after awhile but I'm not sure what the conditions are. The same code works locally always. Any idea what could be the issue?
from pydrive.auth import GoogleAuth
gauth = GoogleAuth()
gauth.LoadCredentialsFile("mycreds.txt")
gauth.Refresh()
Update: Although I can't directly view the errors, it appears trying to refresh authentication tokens on a foreign machine is forbidden. An alternative solution was to go into google cloud and create a service account key for my webapp. I downloaded the key as a json and use that file for authentication.
Additionally, it seems the service account has its own google drive account that isn't easy to access with my browser (but I could see/control it using pydrive in a terminal). For convenience, I shared a folder using my personal gdrive account to the service accounts email. So now I have the service account save files to that shared folder and it is easy for me to see and control the contents using my personal account
from pydrive.auth import GoogleAuth
gauth = GoogleAuth()
from oauth2client.service_account import ServiceAccountCredentials
scope = ["https://www.googleapis.com/auth/drive"]
gauth.credentials = ServiceAccountCredentials.from_json_keyfile_name('client_secrets_serviceacct.json', scope)
gauth.Authorize()
drive = GoogleDrive(gauth)
file = drive.CreateFile({'title': 'testing.txt', 'parents' : [{'id' : 'mygdrivefolderid'}]})
file.Upload()

How to troubleshoot "Value cannot be null. Parameter name: baseUri"

I need help diagnosing this error. Others get it on various platforms (youtube, for example) but seems not solved for most of them. For those who do report success, their solutions haven't work for me.
I'm using Google Drive API and I receive this error when attempting to upload to Google Drive.
My code was working fine for a long time; suddenly, I get this error. After research, I determined that I haven't reached a quota, and that these API are enabled:
Debuglet Controller API
Drive API
Google Cloud Dataflow API
Google Cloud Dataproc API
Google Cloud Deployment Manager API
Google Cloud Deployment Manager V2 API
Google Cloud Storage
Google Cloud Storage JSON API
Google Compute Engine Autoscaler API
Google Compute Engine Instance Group Manager API
Google Compute Engine Instance Group Updater API
Google Compute Engine Instance Groups API
Google Container Engine API
Google Machine Learning API
Here's my code:
string fileName = #"c:\temp\MyPicture.jpg";
string fileTitle = #"TEST-DELETE-ME.jpg";
string fileDescription = #"Test file name";
string fileType = "image/jpeg";
string parentId = "zmzmzmzmzmzmzmzmzmz";
Google.Apis.Drive.v2.DriveService service = (Google.Apis.Drive.v2.DriveService)Service;
Google.Apis.Drive.v2.Data.File body = new Google.Apis.Drive.v2.Data.File();
body.Title = fileTitle;
body.Description = fileDescription;
body.MimeType = fileType;
body.Parents = new List<ParentReference> { new ParentReference() { Id = parentId } };
byte[] byteArray = System.IO.File.ReadAllBytes(fileName);
System.IO.MemoryStream stream = new System.IO.MemoryStream(byteArray);
Google.Apis.Drive.v2.FilesResource.InsertMediaUpload request = service.Files.Insert(body, stream, fileType);
Google.Apis.Upload.IUploadProgress progress = request.Upload();
Google.Apis.Drive.v2.Data.File file = request.ResponseBody;
if (file == null)
{
//Here we are, and we shouldn't be!
//progress.exception.message =
//
//Value cannot be null.
//Parameter name: baseUri
}
When I look at Drive API settings, these are the configurations:
No icons (there are boxes to set 256x265, 128x128, 64x64, 32x32, and 16x16 all are blank)
The application name and short and long descriptions are all blank and optional.
For Drive Integration, all boxes and checkboxes are blank or unchecked. Specifically:
"Automatically show OAuth 2.0 consent..." is unchecked.
"Open URL" is blank.
Default and secondary MIME types and file extensions are blank
"Allow users to create new documents..." is unchecked
"Allow users to open multiple files..." is unchecked
"Allow users to open files that can be converted..." is unchecked
"This application can be launched and works properly in a mobile browser" is unchecked.
Users don't use the Google Drive UI to create documents via my application, and is not meant to be used on a mobile browser. My application only uploads PDF files to users' accounts.
My application has been working for months with no problems, now suddenly seeing this error.
I have tried disabling all API's and then re-enabling them. No dice.
I have tried using a new client id and secret. No dice.
I have tried using a new gmail address and creating a new client id and secret. No dice.
I can't possibly be the only person in the world with this problem. Can anyone help me troubleshoot this?
The underlying issue is like an authorization issue or some other error with the request. However, there's a bug in the .NET client that is masking the error.
See https://github.com/google/google-api-dotnet-client/issues/456

Database and DB provider for hybrid mobile app

I am new to hybrid mobile app development. I am coming from web based development background so bit perplexed.
I zeroed down on Apache/Cordova for build/packaging my hybrid mobile app. This app would be hosted on all 3 major stores. After my initial research, I got a good flavor of UI pieces/frameworks e.g. Angular, Bootstrap, etc. One thing where I got so confused is back-end storage, services and provider. In other words,
What storage services do i need for storing and pulling data (not offline app data)?
Based on storage service how do I decide on provider. Any guidance?
Best way for making calls for all my CRUD operations?
Do I need any kind of server side operations or client side JS would suffice?
Thanks for your help.
You can use Azure Mobile service to store and pull data, each mobile service comes with database. You can try out the trial version to see whether it meets your requirement.
Follow the below steps to add Azure mobile service to your project through Visual Studio:
1.) Right click on project node and select Add --> Connected Services.
2.) Sign-in with your Azure account. Click on Create Service to create new mobile service.
3.) Select the newly created mobile service and click Ok.
4.) It will add service.js, which contains Azure mobile service object.
5.) You can use Azure mobile service object to perform CRUD operations like
var CordovaAppClient
document.addEventListener("deviceready", function () {
CordovaAppClient = new WindowsAzure.MobileServiceClient(
"https://Dummyapp.azure-mobile.net/",
"IsBLy-----ScCqDMuCCZqVlF------");
});
function ReadData()
{
var table = CordovaAppClient.getTable("Item");
var query = table.where({ complete: true });
query.read().then(function(items)
{
listItems = $.map(items, function (item) {
alert(item.text);
});
});
}
function InsertData()
{
var table = CordovaAppClient.getTable("Item");
var inputTest = $('#txtData').val();
table.insert({ text: inputTest, complete: false })
.then(addmessage);
}

Does the GCE/Eclipse magic add client IDs automagically?

Or put another way...
I just moved my app from aaa.appspot.com to a new project (and hence new Client ID) called bbb.appspot.com. When I went to add the new Client Id to my GCE API definitions, it was already there!
So, on the one hand, it's magic :-)
On the other hand, is all of this documented anywhere? I have a slight concern about how I would go about overriding this behaviour if ever I want to manually configure the permitted client IDs.
I assume you are talking about the API annotations for GCE like this:
#ApiMethod(
name = "testAuth",
clientIds = { WEB_CLIENT_ID,
APP1_ANDROID_CLIENT_ID, APP1D_ANDROID_CLIENT_ID,
APP2_ANDROID_CLIENT_ID },
audiences = { Config.WEB_CLIENT_ID }
)
These client ID's come from the API console, where they are created based on your app's package and the hash of your app's certificate.
So, you may create a new GAE project for your new app id, and even create a new console project connected to that new GAE project, but your old console project still exists and still has client id's that are specific to your Android project but independent of your GAE project - so they still work.

Azure MobileServices Live/UAT/Dev environments

I have an azure mobile service that will go live at some point. So I need to create UAT and dev versions which would point to the UAT and dev databases. What I am struggling with is how to create these.
The namespace in my live, UAT and Dev databases need to be the same but if I create a new mobile service called myAppName_UAT, it's going to want to use MyAppName_UAT as the namespace and so will not find any of the tables.
Has anyone overcome this problem? Once the product goes live I'll need to be able to test the mobile apps against the Dev db without affecting live which surely must be a common scenario?
Any advice would be very gratefully received.
Edit: What I'm specifically after is how to manage the multiple environments within the Azure Portal. I can deploy all the other components of my UAT environment but I'm stuck on the mobile service.
I am not asking for a way for my applications to switch config files or to migrate data between databases. Does anyone have any experience of running azure applications with multiple components where they ran multiple mobile services?
Do you use a Version Control? For me, you just need to create branches to separate the 'UAT' and 'dev' versions.
About the databases:
You can use web.config transformations to switch the connection string between your databases.
http://msdn.microsoft.com/en-us/library/dd465326.aspx
How do I use Web.Config transform on my connection strings?
=================================================================================
Update:
Ok, now I understood what you want.
Create your two versions of mobile services:
1-Log in Windows Azure Management Portal (http://manage.windowsazure.com)
2-Create your test mobile services (if you already have then, skip this step):
2.1- New -> Compute -> Mobile Services
2.2- Url - MyMobileServicesTest
2.3- Database -> Create a new (test db).
3-Create your production mobile services (if you already have then, skip this step):
2.1- New -> Compute -> Mobile Services
2.2- Url - MyMobileServicesProduction
2.3- Database -> Create a new (production db).
Right now, you have two different versions.
Using Windows Azure SDK:
//public static MobileServiceClient MobileService = new MobileServiceClient(
// "AppUrl",
// "AppKey"
//);
Pay attention: AppUrl will be "MyMobileServicesTest.azure-mobile.net/" or "MyMobileServicesProduction.azure-mobile.net/". The app key, each environment will have it's own. You can store this settings in a config file and switch according to what you are doing.
More information:
http://www.windowsazure.com/en-us/develop/mobile/tutorials/get-started-with-data-dotnet/
Multiple mobile services can share the same database. You only need to specify the same schema name in web.config in each mobile service:
<appSettings>
<add key="MS_MobileServiceName" value="MyAppName" />
</appSettings>
Updated:
The setting above only works in localhost, but not after publishing to live.
Need to do the following trick in order to make it work. Just hard code the schema name into function OnModelCreating. This way the database schema name will not depend on the mobile service name any more:
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
string schema = "MyAppName"; // ServiceSettingsDictionary.GetSchemaName();
if (!string.IsNullOrEmpty(schema))
{
modelBuilder.HasDefaultSchema(schema);
}
modelBuilder.Conventions.Add(
new AttributeToColumnAnnotationConvention<TableColumnAttribute, string>(
"ServiceTableColumn", (property, attributes) => attributes.Single().ColumnType.ToString()));
}

Resources