helloxielan 2016-06-09 18:41 采纳率: 0%
浏览 30

Polymer.js + OAuth2

Is there an example out there which describes how to implement an OAuth2 authentication in the frontend based on Polymer.js?

I just found some examples that describe the procedure for AJAX, which is also part of the Polymer element set. So how to go on ahead?

  • 写回答

1条回答 默认 最新

  • ??yy 2016-08-15 07:33
    关注

    I found a git repo here which have demo. So you can take a look.

      <oauth-user></oauth-user>
    
      <polymer-element name="oauth-user">
        <template>
            <oauth-authenticator id="authenticator" client_id="282331888208-06mufq54k942624lv803nlm6kvlq76fr.apps.googleusercontent.com" scopes="https://www.googleapis.com/auth/userinfo.profile" on-authenticated="{{authenticated}}"></oauth-authenticator>
            <core-ajax auto id="ajax" url="{{url}}" headers="{{headers}}" handleAs="json" on-core-response="{{ajaxResponse}}"></core-ajax>
            <p>{{greeting}}</p>
        </template>
        <script>
            Polymer({
                url: '',
                greeting: '...',
    
                authenticated: function(event){
                  var token = event.detail.token;
                  this.headers = {'Authorization': 'Bearer ' + token};
                  this.url = "https://www.googleapis.com/oauth2/v1/userinfo?alt=json";
                },
    
                ajaxResponse: function(event, response) {
                  this.greeting = 'Hello ' + response.response.name + '!';
                }
            });
        </script>
      </polymer-element>
    

    You can see there're event handler so you can redirect user or update screen. There're also a url to get user info.

    评论

报告相同问题?

悬赏问题

  • ¥15 如何删除这个虚拟音频
  • ¥50 hyper默认的default switch
  • ¥15 网站打不开,提示502 Bad Gateway
  • ¥20 基于MATLAB的绝热压缩空气储能系统代码咨询
  • ¥15 R语言建立随机森林模型出现的问题
  • ¥20 unity内置语言切换的按钮设置
  • ¥15 中级微观经济学,生产可能性边界问题
  • ¥15 TCP传输时不同网卡传输用时差异过大
  • ¥15 请各位看看我写的属于什么算法,或者有更正确的写法?
  • ¥15 html5 qrcode 扫描器