1 Star 0 Fork 0

neocxf / oauth-sdk-js

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README

Trivago JavaScript oauth SDK

This package provides possibility for third party applications to log in with trivago.

Important notes:

  1. This library uses native es6 Promise. If you need support IE9+ please define a polyfill in your application.

  2. This library works only in browser environments.

Client ID

First of all you need to get a client ID.

If you don't have one, please send a request to Christina.Gkofa@trivago.com

How to start

Include trv.sdk.js as a script in your application or use it as a dependency in your code. As a result you should have trvOauthSdk function available in your code.

Next call the initializer function trvOauthSdk to register your clientId. This returns an object with authorize method in it.

Additionally you can pass an options object in order set up scopes. See API reference for more details.

Script tag

const sdk = trvOauthSdk('your-client-id');
sdk.authorize();

CommonJS

const init = require('trv-oauth-sdk');
const sdk = init('your-client-id');
sdk.authorize();

Scopes

We have several predefined scopes that you can use at the moment:

  • personal_info : Access Personal Information (personal data like email, name, address, country)
  • hotel_info : Access Hotel Information (hotel name, hotel id, hotel location)
  • hotel_analytics : Access Hotel Performance Analytics
  • billing : Access Billing Information

If you don't pass any scopes, default one will be used (personal_info).

API reference

trvOauthSdk(clientId, options)

Method to initialize your application. Returns an object with authorize method in it. Throws an error if clientId was not specified or was not a string.

clientId <string> required

A clientId provided by trivago in order to make possible to log in with trivago.

options <object> optional

options.scope string:

Oauth scope, default: '' (empty string)

authorize()

Method that can be triggered on some action (click on a button) in order to open a popup and enter trivago credentials.

Example

Consider the next example which shows how this library can be used:

<script type="text/javascript" src="path/to/trv.sdk.js"></script>
<script type="text/javascript">
    var sdk = trvOauthSdk('your-client-id');

    var button = document.getElementById('button');
    button.addEventListener('click', onClick);
    function onClick() {
        sdk.authorize().then(function(data) {
            console.log('Well done!', data);
        }).catch(function(err) {
            console.log('Something went wrong', err);
        });
    }
</script>

空文件

简介

暂无描述 展开 收起
JavaScript
取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
JavaScript
1
https://gitee.com/neocxf/oauth-sdk-js.git
git@gitee.com:neocxf/oauth-sdk-js.git
neocxf
oauth-sdk-js
oauth-sdk-js
master

搜索帮助

344bd9b3 5694891 D2dac590 5694891