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

jinhe-oauth2

v0.2.2

Published

oauth2 登录脚本

Downloads

1

Readme

认证授权模块

使用步骤

配置

import OAuth2 from 'oauth2';
OAuth2.setup({
    // 授权服务器地址
    AuthServerBaseAddress: 'http://localhost',
    // 授权路径
    AuthorizePath: '/OAuth/Authorize',
    // Token路径
    TokenPath: '/OAuth/Token',
    // 用户信息路径
    UserInfoPath: '/Api/Account',
    // 用户注册路径
    RegisterPath: '/Api/Account/register',
    // 修改用户密码路径
    ModifyPasswordPath: '/Api/Account/modify/password',
    // 修改用户信息路径
    ModifyUserInfoPath: '/Api/Account/modify/info',
    // 客户端 Id
    ClientId: '',
    // 客户端密钥
    ClientSecret: '',
});

Vue.use(OAuth2)

以上皆为默认值,可根据需要修改

  • [0.2.1] AuthServerBaseAddress

    如果认证服务器是单独部署,请设置该值;否则请设置为空(默认为'')。

使用

可以通过Vue或Vue实例(this)直接访问$User对象。

this.$User.passwordLogin('22222', '22222').then(() => {
      console.dir(this.$User.AccessToken)
}).catch(ex=>{
	alert(ex)
})
let token = Vue.$User.AccessToken

$User提供的方法

  • clientLogin():客户端登录。以客户端的身份(clientId)登录,所以不需要用户名和密码。
  • passwordLogin(username, password) :密码登录。
  • logout():退出登录。
  • register(username, password):注册新用户。
  • modifyPassword(oldPwd, newPwd):修改密码(前提是已登录)。成功后需要重新登录。
  • modifyUserInfo(info):修改用户的基本信息(前提是已登录)。

以上皆为异步方法,可以通过异步方式或promise的方式调用。

如果方法没有执行成功,将抛出错误异常,请使用try-catch。

$User提供的属性

  • AccessToken: 访问令牌。
  • UserInfo : 用户的基本信息。
  • Logined :用户是否已登录。

在需要授权的请求中添加配置

 config.headers["Authorization"] = "bearer " + AccessToken;

UserInfo的详细字段:

{
	UserName, // 用户名,即登录名
	RealName, // 真实姓名
	Sex, // 性别 0男 1女 2未知
	Email, // 邮箱
	PhoneNumber, // 手机号码
	SecurityStamp, // 秘钥
}