@3fv/atlassian-oauth-connect 中文文档教程

发布于 3年前 浏览 25 项目主页 更新于 3年前

Atlassian OAuth 2 (3LO) Browser/Server Client

Install

这是一个正确配置的混合模块, 所以 commonjs & module/esm 运行时是 支持,这意味着 browser & node 环境可以让你整个 不包括 decode 功能的库, 我最终会转换为浏览器支持 使用 cryptojs,但它的功能是透明的 现在在任何环境中

yarn add @3fv/atlassian-oauth-connect

Example Implementation (not for prod use)

Prequistes

首先,确保您已经通过您选择的包管理器 brewaptpacman< 安装了 direnv /code> 等...

Setup

.envrc.templace 复制到 .envrc 并填写所有缺失的字段。 此外,范围列表健壮,但目的是 显示每个当前可用的范围,所以,继续 将其与您需要的配对。

使用您在Atlassian Developer Console 配置您的应用程序时输入/收到的值填充您的重定向 URI、客户端 ID 和客户端密码

警告:如前所述,这只是一个示例; 在现实世界的场景中,配置将来自另一个系统,如 AWS AppConfig,具有适当的秘密管理等。

首先,复制文件:cp .envrc.template .envrc

接下来,从上述 Atlassian Developer Console 应用注册中填充您应用的值。

# IN CASE YOUR SHELL DOESN'T DO THIS FOR YOU
PATH_add $PWD/node_modules/.bin

# SCOPES FOR AUTHORIZATION.
# THEY MUST BE SPACE DELIMITED
export ATLASSIAN_SCOPE="\
  read:me \
  offline_access \
  read:jira-user \
  read:jira-work \
  write:jira-work \
  manage:jira-project \
  manage:jira-configuration \
  manage:jira-webhook \
  read:confluence-content.all \
  read:confluence-content.summary \
  write:confluence-content \
  write:confluence-space \
  write:confluence-file \
  read:confluence-props \
  write:confluence-props \
  manage:confluence-project \
  manage:confluence-configuration \
  search:confluence"

# APP REGISTRATION DETAILS
export ATLASSIAN_REDIRECT_URI=<YOUR_ATLASSIAN_REDIRECT_URI>
export ATLASSIAN_CLIENT_ID=<YOUR_ATLASSIAN_CLIENT_ID>
export ATLASSIAN_CLIENT_SECRET=<YOUR_ATLASSIAN_CLIENT_SECRET>

Run the example

示例服务器是一个非常基本的 html 页面和 express web 服务器,它们一起作为一个相当完整的工具用于 测试与 验证 atlassian 连接集成。

来源在这里 ./src/example/server.ts & ./src/example/index.html

# Install Deps
yarn

# Build & Run Example Server
yarn example:server:start

现在你可以打开浏览器到 http://localhost:4000 玩玩

Hackup to play with Atlassian Connect

我想如果这不容易,你可能会生气, 所以它都是脚本化

的以监视模式启动打字稿编译器 和服务器通过 nodemon,只需运行以下

yarn run example:server:dev

Features

  • getAccessibleResources() queries for all resources (projects & spaces) for which a user accepted grants. Here's an example response.
[
  {
    "id": "00000000-0000-0000-0000-000000000000",
    "url": "https://3fv.atlassian.net",
    "name": "3fv",
    "scopes": [
      "manage:confluence-configuration",
      "search:confluence",
      "write:confluence-props",
      "read:confluence-props",
      "write:confluence-file",
      "write:confluence-space",
      "write:confluence-content",
      "read:confluence-content.summary",
      "read:confluence-content.all"
    ],
    "avatarUrl": "https://site-admin-avatar-cdn.prod.public.atl-paas.net/avatars/240/triangle.png"
  },
  {
    "id": "00000000-0000-0000-0000-000000000000",
    "url": "https://3fv.atlassian.net",
    "name": "3fv",
    "scopes": [
      "manage:jira-configuration",
      "manage:jira-project",
      "manage:jira-webhook",
      "write:jira-work",
      "read:jira-work",
      "read:jira-user"
    ],
    "avatarUrl": "https://site-admin-avatar-cdn.prod.public.atl-paas.net/avatars/240/triangle.png"
  }
]
  • retrieveAccessToken() 代码到令牌交换

  • getUserProfile( ) 检索当前用户配置文件。

{
  "account_id": "0000000000000",
  "email": "aaaa@bbbbbbbb.com",
  "name": "Jonathan Glanz",
  "picture": "https://secure.gravatar.com/avatar/...",
  "account_status": "active",
  "last_updated": "2021-11-15T14:49:38.747Z",
  "nickname": "Jonathan Glanz",
  "locale": "en-US",
  "extended_profile": {
    "job_title": "Software Engineer",
    "team_type": "Software Development"
  },
  "account_type": "atlassian",
  "email_verified": true
}
  • Token refresh rolling functionality; all the requirements to implement refresh token rolling, including the actual refresh token (if you specified the offline_access scope) & the expiration data, so you can implement your own refresh token rolling or wait for me to find a reason :grin:

Todo

  • [ ] Signature Verification (OOB the atlassian-jwt package chucks errors when verifying the returned tokens)
  • [ ] Caching, right now, if you call getUserProfile, retrieveAccessToken, etc., every call no matter identical params or not, query the endpoints; so this is kind of important
  • [ ] Unit tests would be a good idea (started & configured, just not implemented :smile:)
  • [ ] Plus a few e2e cypress tests (started)

Credit

@jglanz 3FV 在#NYC 用爱写成。 享受

Atlassian OAuth 2 (3LO) Browser/Server Client

Install

It's a properly configured hybrid module, so both commonjs & module/esm runtimes are supported, which means that both browser & node environments can you the entire library excluding the decode functionality, which I'll eventually convert for browser support using cryptojs, but it's transparently functional in any evironment now

yarn add @3fv/atlassian-oauth-connect

Example Implementation (not for prod use)

Prequistes

First, make sure you've got direnv installed via your package manager of choice brew, apt, pacman, etc…

Setup

Copy .envrc.templace to .envrc and fill in all the missing fields. Also, the scope list is robust, but the purpose is to show near every currently available scope, so, go ahead and pair it down to what you need.

Populate your redirect URI, client id, and client secret with the values you entered/received Atlassian Developer Console when your configured your app

WARNING: As mentioned, this is just an example; in a real world scenario the configuration would come from another system like AWS AppConfig with appropriate secret management, etc.

First, copy the file: cp .envrc.template .envrc

Next, populate your app's values from the aforementioned Atlassian Developer Console App Registration.

# IN CASE YOUR SHELL DOESN'T DO THIS FOR YOU
PATH_add $PWD/node_modules/.bin

# SCOPES FOR AUTHORIZATION.
# THEY MUST BE SPACE DELIMITED
export ATLASSIAN_SCOPE="\
  read:me \
  offline_access \
  read:jira-user \
  read:jira-work \
  write:jira-work \
  manage:jira-project \
  manage:jira-configuration \
  manage:jira-webhook \
  read:confluence-content.all \
  read:confluence-content.summary \
  write:confluence-content \
  write:confluence-space \
  write:confluence-file \
  read:confluence-props \
  write:confluence-props \
  manage:confluence-project \
  manage:confluence-configuration \
  search:confluence"

# APP REGISTRATION DETAILS
export ATLASSIAN_REDIRECT_URI=<YOUR_ATLASSIAN_REDIRECT_URI>
export ATLASSIAN_CLIENT_ID=<YOUR_ATLASSIAN_CLIENT_ID>
export ATLASSIAN_CLIENT_SECRET=<YOUR_ATLASSIAN_CLIENT_SECRET>

Run the example

The example server is a very basic html page and express web server that together function as a fairly complete tooling for testing & verifyingthe atlassian connect integration.

The source is here ./src/example/server.ts & ./src/example/index.html

# Install Deps
yarn

# Build & Run Example Server
yarn example:server:start

Now you can open a browser to http://localhost:4000 and play around

Hackup to play with Atlassian Connect

I figured you'd probably get annoyed if this wasn't easy, so it's all scripted

To start up the typescript compiler in watch mode and server via nodemon, just run the following

yarn run example:server:dev

Features

  • getAccessibleResources() queries for all resources (projects & spaces) for which a user accepted grants. Here's an example response.
[
  {
    "id": "00000000-0000-0000-0000-000000000000",
    "url": "https://3fv.atlassian.net",
    "name": "3fv",
    "scopes": [
      "manage:confluence-configuration",
      "search:confluence",
      "write:confluence-props",
      "read:confluence-props",
      "write:confluence-file",
      "write:confluence-space",
      "write:confluence-content",
      "read:confluence-content.summary",
      "read:confluence-content.all"
    ],
    "avatarUrl": "https://site-admin-avatar-cdn.prod.public.atl-paas.net/avatars/240/triangle.png"
  },
  {
    "id": "00000000-0000-0000-0000-000000000000",
    "url": "https://3fv.atlassian.net",
    "name": "3fv",
    "scopes": [
      "manage:jira-configuration",
      "manage:jira-project",
      "manage:jira-webhook",
      "write:jira-work",
      "read:jira-work",
      "read:jira-user"
    ],
    "avatarUrl": "https://site-admin-avatar-cdn.prod.public.atl-paas.net/avatars/240/triangle.png"
  }
]
  • retrieveAccessToken() for code to token exchange

  • getUserProfile() to retrieve the current user profile.

{
  "account_id": "0000000000000",
  "email": "aaaa@bbbbbbbb.com",
  "name": "Jonathan Glanz",
  "picture": "https://secure.gravatar.com/avatar/...",
  "account_status": "active",
  "last_updated": "2021-11-15T14:49:38.747Z",
  "nickname": "Jonathan Glanz",
  "locale": "en-US",
  "extended_profile": {
    "job_title": "Software Engineer",
    "team_type": "Software Development"
  },
  "account_type": "atlassian",
  "email_verified": true
}
  • Token refresh rolling functionality; all the requirements to implement refresh token rolling, including the actual refresh token (if you specified the offline_access scope) & the expiration data, so you can implement your own refresh token rolling or wait for me to find a reason :grin:

Todo

  • [ ] Signature Verification (OOB the atlassian-jwt package chucks errors when verifying the returned tokens)
  • [ ] Caching, right now, if you call getUserProfile, retrieveAccessToken, etc., every call no matter identical params or not, query the endpoints; so this is kind of important
  • [ ] Unit tests would be a good idea (started & configured, just not implemented :smile:)
  • [ ] Plus a few e2e cypress tests (started)

Credit

Written with love in #NYC by @jglanz 3FV. Enjoy

    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文