Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

wxtoken

Package Overview
Dependencies
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

wxtoken

weixin authorization

  • 0.2.7
  • latest
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

wxAuth v0.1.0

用于微信授权和微信签名

Installation

Using npm: $ npm i wxAuth -S

In project:

import wxAuth from "wxAuth";

const WxInstance = WxAuth.getInstance();

const authHttp = () => {
  const searchParams = locationSearch(window.location.search);
  return WxInstance.wxAuth(loginApi.wxGetJsapiSignature, loginApi.wxGetAuth, {
    auth: {
      code: searchParams.code,
      type: "parent",
      clientKey: searchParams.clientKey || "",
    },
    signature: {
      clientKey: searchParams.clientKey || "",
      url: window.location.href.split("#")[0],
    },
  });
};

// vue-router beforeEach
xport function routerBeforeEachFunc(to, from, next) {
  authHttp()
    .then((res) => {
      // 已授权
      if (res.status === 'authed') {
        // 判断是否已经获取了用户信息,如果没有获取,则在此处获取
      } else if (res.status === 'failed') {
        // 表示授权失败
        // eslint-disable-next-line no-invalid-this
        this.$toast.fail(res.message)
      }
      next()
    })
    .catch(() => {
      // 如果是生产环境,则需要重定向到微信授权页面,进入到此处,说明url上没有code,session中也没有token
      if (process.env.NODE_ENV === 'production') {
        WxInstance.wxAuthRedirect()
      } else {
        // 开发环境,可以在此处写入token信息到session中
        next()
      }
    })
}

Keywords

FAQs

Package last updated on 16 Apr 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc