Skip to content

Commit

Permalink
Updates doc & post usage
Browse files Browse the repository at this point in the history
  • Loading branch information
nicodecleyre committed May 13, 2023
1 parent 76a3075 commit 8eeaa1c
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 8 deletions.
15 changes: 8 additions & 7 deletions docs/docs/user-guide/using-proxy-url.md
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
# Configure CLI for Microsoft 365 to use Proxy
# Configure CLI for Microsoft 365 to use a proxy

If you are behind a corporate proxy, you may need to configure the CLI for Microsoft 365 to use a proxy server to access Microsoft 365 services. You can configure a proxy URL using the [cli config set](/docs/docs/cmd/cli/config/config-set.md) command.
If you are behind a corporate proxy, you'll have to configure CLI for Microsoft 365 to use a proxy server to access Microsoft 365 services. You can configure a proxy URL using the [cli config set](/docs/docs/cmd/cli/config/config-set.md) command.

## Understanding Proxy URL

Before configuring the proxy, it's important to understand the different parts of a proxy URL. A proxy URL typically consists of the following elements:

- **Protocol**: The protocol used by the proxy server, such as HTTP, HTTPS, or SOCKS.
- **Username and Password**: If the proxy server requires authentication, you will need to provide a username and password.
- **Host**: The hostname or IP address of the proxy server.
- **Port number**: The port number on which the proxy server is listening. Defaults to 80 when not provided.
- **protocol**: The protocol used by the proxy server, such as `HTTP`, `HTTPS`, or `SOCKS`
- **username and password**: if the proxy server requires authentication, you will need to provide a username and password
- **host**: the hostname or IP address of the proxy server
- **port number**: the port number on which the proxy server is listening. Defaults to 443 for the `HTTPS` protocol, otherwise it defaults to 80 when not provided

## Configuring Proxy URL
To configure CLI for Microsoft 365 to use a proxy, you need to execute the m365 cli config set command with the following syntax:

To configure CLI for Microsoft 365 to use a proxy, you need to execute the `m365 cli config set` command with the following syntax:

`m365 cli config set --key proxyUrl --value 'http://username:password@proxy.contoso.com:8080'`

Expand Down
20 changes: 20 additions & 0 deletions src/request.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -437,6 +437,26 @@ describe('Request', () => {
});
});

it('returns response of a successful GET request, with a proxy url and defaults port to 443', (done) => {
const config = Cli.getInstance().config as Configstore;
sinon.stub(config, 'get').callsFake(() => 'https://proxy.contoso.com');

sinon.stub(_request as any, 'req').callsFake((options) => {
_options = options;
return Promise.resolve({ data: {} });
});

_request
.get({
url: 'https://contoso.sharepoint.com/'
})
.then(() => {
done();
}, (err) => {
done(err);
});
});

it('returns response of a successful GET request, with a proxy url with username and password', (done) => {
const config = Cli.getInstance().config as Configstore;
sinon.stub(config, 'get').callsFake(() => 'http://username:password@proxy.contoso.com:8080');
Expand Down
2 changes: 1 addition & 1 deletion src/request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ class Request {
private createProxyConfigFromString(url: string): AxiosProxyConfig {
const parsedUrl = new URL(url);
const hostname = parsedUrl.hostname;
const port = parsedUrl.port || 80;
const port = parsedUrl.port || (url.toLowerCase().startsWith('https') ? 443 : 80);
let authObject = null;
if (parsedUrl.username && parsedUrl.password) {
authObject = {
Expand Down

0 comments on commit 8eeaa1c

Please sign in to comment.