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 metadata提取的PDF元数据,如何转换为一个Excel
  • ¥15 关于arduino编程toCharArray()函数的使用
  • ¥100 vc++混合CEF采用CLR方式编译报错
  • ¥15 coze 的插件输入飞书多维表格 app_token 后一直显示错误,如何解决?
  • ¥15 vite+vue3+plyr播放本地public文件夹下视频无法加载
  • ¥15 c#逐行读取txt文本,但是每一行里面数据之间空格数量不同
  • ¥50 如何openEuler 22.03上安装配置drbd
  • ¥20 ING91680C BLE5.3 芯片怎么实现串口收发数据
  • ¥15 无线连接树莓派,无法执行update,如何解决?(相关搜索:软件下载)
  • ¥15 Windows11, backspace, enter, space键失灵