Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

<firebase-auth> does allow access to Google REST APIs through <iron-ajax> #108

Closed
dwberry opened this issue Sep 5, 2016 · 1 comment
Closed

Comments

@dwberry
Copy link

dwberry commented Sep 5, 2016

Description

Sign in with Google through firebase-auth will not allow access to google REST APIs.

Expected outcome

Return JSON response from Google Rest

Actual outcome

Returns: 401 Login Required....

{
 "error": {
  "errors": [
   {
    "domain": "global",
    "reason": "required",
    "message": "Login Required",
    "locationType": "header",
    "location": "Authorization"
   }
  ],
  "code": 401,
  "message": "Login Required"
 }
}

Code

<link rel="import" href="../bower_components/polymer/polymer.html">
<link rel="import" href="../bower_components/polymerfire/polymerfire.html">
<link rel="import" href="../bower_components/iron-image/iron-image.html">
<link rel="import" href="../bower_components/iron-list/iron-list.html">
<link rel="import" href="../bower_components/google-apis/google-apis.html">
<link rel="import" href="../bower_components/iron-ajax/iron-ajax.html">

<link rel="import" href="shared-styles.html">

<dom-module id="doc-create">
  <template>
    <style include="shared-styles">
      :host {
        display: block;
        padding: 10px;
      }
    </style>
      <iron-ajax
        auto
        url="https://www.googleapis.com/drive/v3/about"
        params = "{{ajaxParams}}"
        handle-as="json"
        with-credentials
        last-response="{{ajaxResponse}}"></iron-ajax>
    <div class="card">
      <template is="dom-repeat" items="[[ajaxResponse]]">
        <div class="horizontal-section">
        <p>[[index]]: [[item.title]]</p>
        </div>
      </template>
    </div>
    <div class="card">
        Response Data: [[ajaxResponse]]
        Params: [[ajaxParams.fields]]
    </div>
  </template>
  <script>
    Polymer({
      is: 'doc-create',
      properties: {
          fields: {
              type: String,
              value: 'user'
          },
          apikey: {
              type: String,
              value: 'ya29.CjBVA-xVkMLL1f7j9bw....'
          },
          ajaxParams: {
              type: String,
              computed: 'processParams(fields, apikey)'
          }
      },
        processParams: function(fields, apikey) {
            return {
                fields: fields,
                key: apikey
            };
        }
    });
  </script>
</dom-module>

Steps to reproduce

Call to Firebase-auth with:

 signIn: function() {
          this.$.auth.signInWithPopup().then(function(result){
            var token = String(result.credential.accessToken);
            console.log(token);
            this.apitoken= token;
          });

Added scopes to Polymerfire/firebase-auth:
Line 248:

        _providerFromName: function(name) {
          switch (name) {
            case 'facebook': return new firebase.auth.FacebookAuthProvider();
            case 'github': return new firebase.auth.GithubAuthProvider();
            case 'google': {
              var provider = new firebase.auth.GoogleAuthProvider();
              provider.addScope('https://mail.google.com/');
              provider.addScope('https://www.googleapis.com/auth/drive');
            } return provider;
            case 'twitter': return new firebase.auth.TwitterAuthProvider();
            default: this.fire('error', 'Unrecognized firebase-auth provider "' + name + '"');
          }
        },
@mbleigh
Copy link
Contributor

mbleigh commented Sep 9, 2016

Duplicate of #103, see my comment here.

@mbleigh mbleigh closed this as completed Sep 9, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants