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

bsm-oauth

v1.1.0

Published

BSM Auth를 JavaScript에서 쉽게 사용할 수 있는 라이브러리

Downloads

18

Readme

BSM OAuth JS

BSM Auth의 OAuth기능을 JS에서 사용하기 쉽게 만들어주는 라이브러리입니다.

설치

$ npm install bsm-oauth

사용하기

TypeScript

import BsmOauth, {
  BsmOauthError,
  BsmOauthErrorType,
  BsmUserRole,
  BsmStudentResource,
  BsmTeacherResource
} from 'bsm-oauth';

// BSM OAuth 객체 초기화
const bsmOauth = new BsmOauth(BSM_AUTH_CLIENT_ID, BSM_AUTH_CLIENT_SECRET);

// 인증코드로 토큰 발급
const token = await bsmOauth.getToken(authCode);

// 토큰으로 유저 정보 가져오기
const resource = await bsmOauth.getResource(token);

// 가져온 유저 정보 확인
console.log(resource);

JavaScript

const {
  BsmOauth,
  BsmOauthError,
  BsmOauthErrorType,
  BsmUserRole,
  BsmStudentResource,
  BsmTeacherResource
} = require('bsm-oauth');

const bsmOauth = new BsmOauth(BSM_AUTH_CLIENT_ID, BSM_AUTH_CLIENT_SECRET);

// 인증코드로 토큰 발급
const token = await bsmOauth.getToken(authCode);

// 토큰으로 유저 정보 가져오기
return await bsmOauth.getResource(token);

// 가져온 유저 정보 확인
console.log(resource);

예외 처리하기

try {
  const token = await bsmOauth.getToken(authCode);
  await bsmOauth.getResource(token);
} catch (error) {
  if (!(error instanceof BsmOauthError)) {
    return;
  }
  if (error.type === BsmOauthErrorType.INVALID_CLIENT) {
    // 클라이언트 정보가 잘못되었을 때
  }
  if (error.type === BsmOauthErrorType.AUTH_CODE_NOT_FOUND) {
    // 인증코드를 찾을 수 없을 때
  }
  if (error.type === BsmOauthErrorType.TOKEN_NOT_FOUND) {
    // 토큰을 찾을 수 없을 때
  }
}

학생, 선생님계정 구분하기

role 속성으로 구분할 수 있습니다.

// TypeScript에서는 role로 타입을 추론해야 학생 및 선생님 정보에 접근 가능합니다.
if (resource.role === BsmUserRole.STUDENT) {
  // 학생 이름과 번호 확인
  console.log(resource.student.name, resource.student.studentNo);
}
if (resource.role === BsmUserRole.TEACHER) {
  // 선생님 이름 확인
  console.log(resource.teacher.name);
}

학생, 선생님의 고유 정보에 바로 접근하기

getRawResource 메서드로 원시 데이터를 가져올 수 있습니다.

const rawResource: RawBsmOAuthResource = await bsmOauth.getRawResource(token);
// 학생 또는 선생님의 이름 확인
console.log(rawResource.name);

// 학생의 번호 확인 (만약 resource.role이 TEACHER일 경우 undefined가 출력됩니다.)
console.log(rawResource.studentNo);