@vssue/api-bitbucket-v2
Advanced tools
Comparing version 0.7.5 to 0.8.0
@@ -11,3 +11,3 @@ import axios from 'axios'; | ||
export default class BitbucketV2 { | ||
constructor({ baseURL = 'https://bitbucket.org', owner, repo, clientId, clientSecret, state, proxy, }) { | ||
constructor({ baseURL = 'https://bitbucket.org', owner, repo, clientId, state, }) { | ||
this.baseURL = baseURL; | ||
@@ -17,5 +17,3 @@ this.owner = owner; | ||
this.clientId = clientId; | ||
this.clientSecret = clientSecret; | ||
this.state = state; | ||
this.proxy = proxy; | ||
this.$http = axios.create({ | ||
@@ -51,3 +49,4 @@ baseURL: 'https://api.bitbucket.org/2.0', | ||
redirect_uri: window.location.href, | ||
response_type: 'code', | ||
response_type: 'token', | ||
state: this.state, | ||
}); | ||
@@ -63,46 +62,22 @@ } | ||
* @remarks | ||
* If the `code` exists in the query, remove them from query, and try to get the access token. | ||
* If the `access_token` and `state` exist in the query, and the `state` matches, remove them from query, and return the access token. | ||
*/ | ||
async handleAuth() { | ||
const query = parseQuery(window.location.search); | ||
if (query.code) { | ||
const code = query.code; | ||
delete query.code; | ||
const replaceURL = buildURL(getCleanURL(window.location.href), query) + window.location.hash; | ||
window.history.replaceState(null, '', replaceURL); | ||
const accessToken = await this.getAccessToken({ code }); | ||
return accessToken; | ||
const hash = parseQuery(window.location.hash.slice(1)); | ||
if (!hash.access_token || hash.state !== this.state) { | ||
return null; | ||
} | ||
return null; | ||
const accessToken = hash.access_token; | ||
delete hash.access_token; | ||
delete hash.token_type; | ||
delete hash.expires_in; | ||
delete hash.state; | ||
delete hash.scopes; | ||
const hashString = buildQuery(hash); | ||
const newHash = hashString ? `#${hashString}` : ''; | ||
const replaceURL = `${getCleanURL(window.location.href)}${window.location.search}${newHash}`; | ||
window.history.replaceState(null, '', replaceURL); | ||
return accessToken; | ||
} | ||
/** | ||
* Get user access token via `code` | ||
* | ||
* @param options.code - The code from the query | ||
* | ||
* @return User access token | ||
* | ||
* @see https://developer.atlassian.com/bitbucket/api/2/reference/meta/authentication#oauth-2 | ||
*/ | ||
async getAccessToken({ code, }) { | ||
const originalURL = concatURL(this.baseURL, 'site/oauth2/access_token'); | ||
const proxyURL = typeof this.proxy === 'function' | ||
? this.proxy(originalURL) | ||
: this.proxy; | ||
const { data } = await this.$http.post(proxyURL, buildQuery({ | ||
grant_type: 'authorization_code', | ||
redirect_uri: window.location.href, | ||
code, | ||
}), { | ||
headers: { | ||
'Content-Type': 'application/x-www-form-urlencoded', | ||
}, | ||
auth: { | ||
username: this.clientId, | ||
password: this.clientSecret, | ||
}, | ||
}); | ||
return data.access_token; | ||
} | ||
/** | ||
* Get the logined user with access token. | ||
@@ -294,3 +269,3 @@ * | ||
*/ | ||
async getCommentReactions() { | ||
async getCommentReactions(options) { | ||
throw new Error('501 Not Implemented'); | ||
@@ -301,3 +276,3 @@ } | ||
*/ | ||
async postCommentReaction() { | ||
async postCommentReaction(options) { | ||
throw new Error('501 Not Implemented'); | ||
@@ -304,0 +279,0 @@ } |
{ | ||
"name": "@vssue/api-bitbucket-v2", | ||
"version": "0.7.5", | ||
"version": "0.8.0", | ||
"description": "Vssue api for bitbucket v2", | ||
@@ -29,6 +29,6 @@ "license": "MIT", | ||
"dependencies": { | ||
"@vssue/utils": "^0.7.5", | ||
"@vssue/utils": "^0.8.0", | ||
"axios": "^0.18.0" | ||
}, | ||
"gitHead": "cf39df438a3c39c60fb2c4cefec26421508cc595" | ||
"gitHead": "4e81dce08ca357b607809c2dce77c5afbdb26ddc" | ||
} |
@@ -14,7 +14,5 @@ import { VssueAPI } from 'vssue'; | ||
clientId: string; | ||
clientSecret: string; | ||
state: string; | ||
proxy: string | ((url: string) => string); | ||
$http: AxiosInstance; | ||
constructor({ baseURL, owner, repo, clientId, clientSecret, state, proxy, }: VssueAPI.Options); | ||
constructor({ baseURL, owner, repo, clientId, state, }: VssueAPI.Options); | ||
/** | ||
@@ -38,18 +36,6 @@ * The platform api info | ||
* @remarks | ||
* If the `code` exists in the query, remove them from query, and try to get the access token. | ||
* If the `access_token` and `state` exist in the query, and the `state` matches, remove them from query, and return the access token. | ||
*/ | ||
handleAuth(): Promise<VssueAPI.AccessToken>; | ||
/** | ||
* Get user access token via `code` | ||
* | ||
* @param options.code - The code from the query | ||
* | ||
* @return User access token | ||
* | ||
* @see https://developer.atlassian.com/bitbucket/api/2/reference/meta/authentication#oauth-2 | ||
*/ | ||
getAccessToken({ code, }: { | ||
code: string; | ||
}): Promise<string>; | ||
/** | ||
* Get the logined user with access token. | ||
@@ -170,7 +156,7 @@ * | ||
*/ | ||
getCommentReactions(): Promise<VssueAPI.Reactions>; | ||
getCommentReactions(options: any): Promise<VssueAPI.Reactions>; | ||
/** | ||
* Bitbucket does not support reactions now | ||
*/ | ||
postCommentReaction(): Promise<boolean>; | ||
postCommentReaction(options: any): Promise<boolean>; | ||
} |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
26036
474
+ Added@vssue/utils@0.8.2(transitive)
- Removed@vssue/utils@0.7.5(transitive)
Updated@vssue/utils@^0.8.0