Tom Russell Tom Russell - 1 year ago 98
Dart Question

How do I generate a Dart client library for my Google Cloud Endpoints API using discoveryapis_generator?

I have an endpoints API that I'm accessing with a Dart client library generated with

. All is well and good except that the generated library doesn't appear to reflect the authentication requirements of my API.

Is it only necessary to somehow create an authenticated
object to pass to my application's
constructor in the following line?

my_api = new MyApi(new BrowserClient());

Is the recommended method for creating the authenticated
object to use the
package as described here? Am I on the right track?

Answer Source

The authentication is not part of the API itself. It is actually the http client that will send the proper http header for user authentication. Assuming you use the standard google auth mechanism, you can use the package as you would for a standard Google API (Drive, etc...).

You will have to create a clientId (google console) and use BrowserOAuth2Flow to get an AuthClient (that extends http.client) and from then do new MyApi(authClient)

I have a (quite old) project where I override the standard behavior of google auth to allow specifying a userId (never really found the doc on that but it works) during authentication with a simple example that use the PlusApi to get the user name but it could work in a similar way for your own api. Maybe that could help

I think you need at least the email scope when calling createImplicitBrowserFlow

There are also samples for using google apis that could help:

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download