npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@blazes/third-party-auth

v1.0.12-test1

Published

于package.json中新增依赖

Downloads

13

Readme

第三方授权

于package.json中新增依赖

"@blazes/third-party-auth": "1.0.6-alpha13"

Apple

初始化

调用appleAuthService.init()完成Apple授权初始化。

appleAuthService.init({
    clientId: "YOUR_APPLE_CLIENT_ID",
    scope: "name email",
    redirectURI: "https://www.example.com",
});

初始化参数AppleInitOption如下:

export interface AppleInitOption {
    clientId: string;
    scope: string;
    redirectURI: string;
    state?: string;
    nonce?: string;
    usePopup?: boolean;
}

clientId:Apple Web授权服务应用ID,从Apple开发者后台获取。

scope:用户信息的请求范围。若无特殊需求,可以使用name email

redirectURI:Apple授权完毕后的授权信息的回调地址,从开发者后台获取。必须保证当前页面host与回调地址相同。

开启授权

调用appleAuthService.startAuth()开启授权,返回值为包含授权结果的``Promise`

appleAuthService.startAuth().then((res: AuthRes) => {
    // handle result here
})

AuthRes数据结构如下:

export interface AuthRes {
    idToken?: string;
    code?: string;
}

其中,Apple授权成功后只需拿到code值。

示例

import { appleAuthService, AuthRes } from '@blazes/third-party-auth';

        appleAuthService.init({
            clientId: "YOUR_APPLE_CLIENT_ID",
            scope: "name email",
            redirectURI: "https://www.example.com",
        });


        const appleLogin = () => {
            appleAuthService.startAuth().then((res: AuthRes) => {
                   const authCode = res.code;
                   // handle apple auth code here
            })
        }})

Facebook

初始化

调用facebookAuthService.init()完成Facebook授权初始化。

facebookAuthService.init({
    appId: "YOUR_FACEBOOK_APP_ID"
})

初始化参数FacebookInitOption如下:

export interface FacebookInitOption {
    appId: string;
    autoLogAppEvents?: boolean;
    xfbml?: boolean;
    version?: string;
}

appId:Facebook应用ID,可从Facebook开发者后台获取。

开启授权

调用facebookAuthService.startAuth()开启授权,返回值为包含授权结果的Promise

facebookAuthService.startAuth().then((res: AuthRes) => {
    // handle result here
})

AuthRes数据结构如下:

export interface AuthRes {
    idToken?: string;
    code?: string;
}

Facebook授权成功后只需拿到idToken值。

示例

import { facebookAuthService } from '@blazes/third-party-auth';

facebookAuthService.init({
    appId: "YOUR_FACEBOOK_APP_ID"
})


const facebookLogin = () => {
    facebookAuthService.startAuth().then(res => {
        const idToken = res.idToken;
            // handle facebook token here
        })
}

Google

初始化

调用gooogleAuthService.init()完成Google授权初始化。

googleAuthService.init({
    clientId: "YOUR_GOOGLE_CLIENT_ID"
})

初始化参数GoogleInitOption如下:

export interface GoogleInitOption {
  clientId: string;
  scope?: string;
}

开启授权

googleAuthService.startAuth().then(res => {
    const code = res.code;
    // handle google code here
})

示例

googleAuthService.init({
    clientId: "YOUR_GOOGLE_CLIENT_ID"
})

const googleLogin = () => {
    googleAuthService.startAuth().then(res => {
        const code = res.code;
        // handle google code here
    })
}

Twitter

添加Polyfill Plugin

于vue.config.js中添加Polyfill Plugin

const NodePolyfillPlugin = require("node-polyfill-webpack-plugin");

module.exports = defineConfig({
  ...
  configureWebpack: {
    plugins: [new NodePolyfillPlugin()],
  },
  ...
});

网络请求代理

Twitter API因为跨域无法直接请求,需要为网络请求设置代理。

third-party-auth组件库内所有的Twitter API请求都发送至/twitterApis,需要在项目中将所有/twitterApis的请求转发至https://api.twitter.com

测试环境代理的配置如下:

 devServer: {
     ...
      "/twitterApis": {
        target: "https://api.twitter.com",
        changeOrigin: true,
        pathRewrite: {
          "^/twitterApis": "/",
        },
      },
     ...
    },

设置回调页面路由

在路由中新增回调页面

import { TwitterCallback } from "@blazes/third-party-auth";
const routes = 
    [
     {
        path: "/callback",
        name: "twitterCallback",
        component: TwitterCallback,
     },
     ...
    ]

初始化

调用twitterAuthService.init完成Twitter授权初始化。

twitterAuthService.init({
    consumerKey: "YOUR_CONSUMER_KEY",
    consumerSecret: "YOUR_CONSUMER_SECRET",
    callbackUrl: "CALLBACK_URL",
})

初始化参数FacebookInitOption如下:

export interface TwitterInitOption {
    consumerKey: string;
    consumerSecret: string;
    callbackUrl: string;
    windowOption?: string;
}

consumerKey:从后台获取

consumerSecr:从后台获取

callbackUrl:Twitter授权完毕后的回调地址。callbackUrl指向上一步所设置的回调页面地址。

windowOption:Twitter授权弹窗参数,可以自定义弹窗宽高。

开启授权

调用twitterAuthService.startAuth()开启授权,返回值为包含授权结果的Promise

const twitterLogin = () => {
    twitterAuthService.startAuth().then((res: AuthRes) => {
        const oauthToken = res.idToken;
        const oauthTokenSecret = res.extra?.oauthTokenSecret;
        // handle twitter result here
    })
}

AuthRes数据结构如下:

export interface AuthRes {
    idToken?: string;
    code?: string;
    extra?: {
        oauthTokenSecret?: string;
    };
}

示例

twitterAuthService.init({
    consumerKey: "YOUR_CONSUMER_KEY",
    consumerSecret: "YOUR_CONSUMER_SECRET",
    callbackUrl: "CALLBACK_URL",
})   

const twitterLogin = () => {
    twitterAuthService.startAuth().then((res: AuthRes) => {
        const oauthToken = res.idToken;
        const oauthTokenSecret = res.extra?.oauthTokenSecret;
        // handle twitter result here
    })
  } 
}