Skip to content
Snippets Groups Projects
Commit 853d0441 authored by michael.minelli's avatar michael.minelli
Browse files

GitlabManager => Add get tokens function

parent c437e155
No related branches found
No related tags found
No related merge requests found
...@@ -2,6 +2,7 @@ import axios from 'axios'; ...@@ -2,6 +2,7 @@ import axios from 'axios';
import GitlabPipeline from '../types/Gitlab/GitlabPipeline'; import GitlabPipeline from '../types/Gitlab/GitlabPipeline';
import GitlabRoute from '../types/Gitlab/GitlabRoute'; import GitlabRoute from '../types/Gitlab/GitlabRoute';
import SharedConfig from '../config/SharedConfig'; import SharedConfig from '../config/SharedConfig';
import GitlabToken from '../types/Gitlab/GitlabToken';
class GitlabManager { class GitlabManager {
...@@ -9,6 +10,19 @@ class GitlabManager { ...@@ -9,6 +10,19 @@ class GitlabManager {
return `${ SharedConfig.gitlab.apiURL }${ route }`; return `${ SharedConfig.gitlab.apiURL }${ route }`;
} }
async getTokens(codeOrRefresh: string, isRefresh: boolean = false, clientSecret: string = ''): Promise<GitlabToken> {
const response = await axios.post<GitlabToken>(`${ SharedConfig.gitlab.URL }/oauth/token`, {
client_id : SharedConfig.login.gitlab.client.id,
client_secret: clientSecret,
grant_type : isRefresh ? 'refresh_token' : 'authorization_code',
refresh_token: codeOrRefresh,
code : codeOrRefresh,
redirect_uri : SharedConfig.login.gitlab.url.redirect
});
return response.data;
}
async getRepositoryPipelines(repoId: number, branch: string = 'main'): Promise<Array<GitlabPipeline>> { async getRepositoryPipelines(repoId: number, branch: string = 'main'): Promise<Array<GitlabPipeline>> {
const response = await axios.get<Array<GitlabPipeline>>(this.getApiUrl(GitlabRoute.REPOSITORY_PIPELINES).replace('{{id}}', String(repoId)), { const response = await axios.get<Array<GitlabPipeline>>(this.getApiUrl(GitlabRoute.REPOSITORY_PIPELINES).replace('{{id}}', String(repoId)), {
params: { params: {
......
interface GitlabToken {
access_token: string;
token_type: string;
expires_in: number;
refresh_token: string;
scope: string;
created_at: number;
}
export default GitlabToken;
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment