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 存储过程或函数中的结果集类型变量如何使用。
    • ¥80 关于海信电视聚好看安装应用的问题
    • ¥15 vue引入sdk后的回调问题
    • ¥15 求一个智能家居控制的代码
    • ¥15 ad软件 pcb布线pcb规则约束编辑器where the object matpcb布线pcb规则约束编辑器where the object matchs怎么没有+15v只有no net
    • ¥15 虚拟机vmnet8 nat模式可以ping通主机,主机也能ping通虚拟机,但是vmnet8一直未识别怎么解决,其次诊断结果就是默认网关不可用
    • ¥20 求各位能用我能理解的话回答超级简单的一些问题
    • ¥15 yolov5双目识别输出坐标代码报错
    • ¥15 这个代码有什么语法错误
    • ¥15 给予STM32按键中断与串口通信