Create a repository OAuth scopes required: repository:admin - bitbucket cloud api
Asked by Eyal David:

Hi Guys

I have been wondering isn't that a risk giving admin permission to OAuth consumer on the entire workspace

when creating repository do i have to be an admin ... ?

can you supply justifications and alternative ways to reduce risk here.... ?

Thanks

Eyal


Answers:
author: Norbert C
body: Hi Eyal,

Thank you for contacting Atlassian Community. My name is Norbert and I'm a Bitbucket Cloud Support Engineer, it's nice to meet you!

I would like to confirm that you're correct. To be able to create a repository in Bitbucket Cloud, you need to create an OAuth consumer, which has a "repository:admin" permission, otherwise you would get an error message which would tell you, that your OAuth key doesn't have the necessary scopes for repository creation.

I'm afraid there's no alternative ways to reduce the risks here. In case you create OAuth consumer and key with a repository:admin permission, I'd suggest you to not to share this key with anyone else.

Please let us know if you have any further question? We're here to help.

Best Regards,  
Norbert  
Atlassian Bitbucket Cloud Support

comments: author: Eyal David
body: Hi [Norbert C](https://community.atlassian.com/t5/user/viewprofilepage/user-id/1190200)

thank you for your fast response and i understand that it can't be achieved.

for more i have problems to git push via the api after i created the repository ...is there and documentation it only show the clone command i need to be able to do git commit push

$ git clone https://x-token-auth:{access_token}[@Bitbucket](/t5/user/viewprofilepage/user-id/1253146).org/user/repo.git

this is the clone ....


author: Norbert C
body: Hi [@Eyal David](/t5/user/viewprofilepage/user-id/4676376)

To be able push using an access token, what I would like to recommend you is to change the .git/config file in the cloned repository, add the following line into the config file under the \[remote "origin"\] section:

```
url = https://x-token-auth:AUTHTOKEN@bitbucket.org/workspace/repository
```

Please let me know how it goes.

Best Regards,  
Norbert  
Atlassian Bitbucket Cloud Support


author: Eyal David
body: Hi

this exactly what i have

```
[remote "origin"] url = https://x-token-auth:MYTOKEN@bitbucket.org/mycompanyworkspace/MYGENERATEDREPO.git fetch = +refs/heads/*:refs/remotes/origin/*
```

any idea ?

Thanks


author: Norbert C
body: Hi [@Eyal David](/t5/user/viewprofilepage/user-id/4676376) ,

This looks good. Can you let me know what happens when you do a "git push" once you have your config setup like this?


author: Eyal David
body: Hi [@Norbert C](/t5/user/viewprofilepage/user-id/1190200)

```
remote: Your credentials lack one or more required privilege scopes.10:51:38  fatal: unable to access 'https://bitbucket.org/transmitsecurity/restored-flexid-ci-2022-01-03.git/mycompanyworkspace/MYGENERATEDREPO.githttps://bitbucket.org/transmitsecurity/restored-flexid-ci-2022-01-03.git/'

: The requested URL returned error: 403 
```

this is what im getting .... BTW the repository is being generated from api ...kind of trying to implement create git repository --- add,commit,push

tried this example as well and got the same error

<https://support.atlassian.com/bitbucket-cloud/docs/push-back-to-your-repository/>

# Configure git to use the oauth token.

- git remote set-url origin "https://x-token-auth:${access_token}@bitbucket.org/${BITBUCKET_REPO_OWNER}/${BITBUCKET_REPO_SLUG}"

# Make changes and commit back. - echo "Made a change in build ${BITBUCKET_BUILD_NUMBER}" \>\> changes.txt -

git add changes.txt

- git commit -m "\[skip ci\] Updating changes.txt with latest build number."

- git push

Thanks

Eyal


author: Eyal David
body: Hi [@Norbert C](/t5/user/viewprofilepage/user-id/1190200)

another question .. trying to set the repository generate by api as private

is_private : true with no success ... im using OAUTH ....

thanks

Eyal


author: Eyal David
body: [@Norbert C](https://community.atlassian.com/t5/user/viewprofilepage/user-id/1190200)

any idea how can i continue here ?


author: Norbert C
body: Hi [@Eyal David](/t5/user/viewprofilepage/user-id/4676376) ,

Please excuse me for the late reply, I was out of office yesterday.

Can you let me know whether your OAuth consumer and key has the "repository:write" scope?

Based on my observation from your error message, I suspect your OAuth consumer doesn't have this scope and that's why it fails.

When I've tried it with the following scope, I was able to push to the repository

![oauthscopes.png](https://community.atlassian.com/t5/image/serverpage/image-id/176605iA047437DC086B70B/image-size/large?v=v2&px=999 "oauthscopes.png")

Please let me know, Eyal.

Best Regards  
Norbert  
Atlassian Bitbucket Cloud Support


author: Eyal David
body: [@Norbert C](/t5/user/viewprofilepage/user-id/1190200) indeed i was missing write permissions i thought that when you have admin permission you get the writ by default .... so thanks for this. .... realy helped me ...

for more by any chance do you know how can i create my repository as private

as i wrote above i did try is_private : true with no success...

can you please help with this as well ?

Thank you very much !!!


author: Eyal David
body: [@Norbert C](/t5/user/viewprofilepage/user-id/1190200)

I see that there is already question on this with no answer ...

<https://community.atlassian.com/t5/Bitbucket-questions/How-to-create-private-repository-via-API-2-0/qaq-p/1202924>


author: Eyal David
body: [@Norbert C](/t5/user/viewprofilepage/user-id/1190200) created another question for is_private : true

Thank you very much for your help


author: Norbert C
body: You're welcome [@Eyal David](/t5/user/viewprofilepage/user-id/4676376) , I'm glad to hear I was able to help


Tags: bitbucket-cloud

cloud