Skip to content

Commit 98eec56

Browse files
Added alias to 'accesstoken get' solving #1369
1 parent 21f5216 commit 98eec56

7 files changed

Lines changed: 57 additions & 23 deletions

File tree

docs/manual/docs/about/comparison-powershell.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ Export-PnPClientSidePageMapping|SharePointPnPPowerShellOnline|
263263
Export-PnPTaxonomy|SharePointPnPPowerShellOnline|
264264
Export-PnPTermGroupToXml|SharePointPnPPowerShellOnline|
265265
Find-PnPFile|SharePointPnPPowerShellOnline|
266-
Get-PnPAccessToken|SharePointPnPPowerShellOnline|[accesstoken get](../cmd/accesstoken-get.md)
266+
Get-PnPAccessToken|SharePointPnPPowerShellOnline|[util accesstoken get](../cmd/util/accesstoken/accesstoken-get.md)
267267
Get-PnPAlert|SharePointPnPPowerShellOnline|
268268
Get-PnPApp|SharePointPnPPowerShellOnline|[spo app get](../cmd/spo/app/app-get.md), [spo app list](../cmd/spo/app/app-list.md)
269269
Get-PnPAppAuthAccessToken|SharePointPnPPowerShellOnline|

docs/manual/docs/about/release-notes.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@
225225

226226
**Global:**
227227

228-
- [accesstoken get](../cmd/accesstoken-get.md) - gets access token for the specified resource [#1072](https://github.com/pnp/office365-cli/issues/1072)
228+
- [util accesstoken get](../cmd/util/accesstoken/accesstoken-get.md) - gets access token for the specified resource [#1072](https://github.com/pnp/office365-cli/issues/1072)
229229

230230
### Changes
231231

docs/manual/docs/cmd/accesstoken-get.md renamed to docs/manual/docs/cmd/util/accesstoken/accesstoken-get.md

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,17 @@
1-
# accesstoken get
1+
# util accesstoken get
22

33
Gets access token for the specified resource
44

55
## Usage
66

77
```sh
8-
accesstoken get [options]
8+
util accesstoken get [options]
9+
```
10+
11+
## Alias
12+
13+
```sh
14+
accesstoken get
915
```
1016

1117
## Options
@@ -23,18 +29,21 @@ Option|Description
2329

2430
## Remarks
2531

26-
The `accesstoken get` command returns an access token for the specified resource. If an access token has been previously retrieved and is still valid, the command will return the cached token. If you want to ensure that the returned access token is valid for as long as possible, you can force the command to retrieve a new access token by using the `--new` option.
32+
!!! attention
33+
The 'accesstoken get' command is deprecated. Please use 'util accesstoken get' instead.
34+
35+
The `util accesstoken get` command returns an access token for the specified resource. If an access token has been previously retrieved and is still valid, the command will return the cached token. If you want to ensure that the returned access token is valid for as long as possible, you can force the command to retrieve a new access token by using the `--new` option.
2736

2837
## Examples
2938

3039
Get access token for the Microsoft Graph
3140

3241
```sh
33-
accesstoken get --resource https://graph.microsoft.com
42+
util accesstoken get --resource https://graph.microsoft.com
3443
```
3544

3645
Get a new access token for SharePoint Online
3746

3847
```sh
39-
accesstoken get --resource https://contoso.sharepoint.com --new
48+
util accesstoken get --resource https://contoso.sharepoint.com --new
4049
```

docs/manual/mkdocs.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ nav:
1111
- login: 'cmd/login.md'
1212
- logout: 'cmd/logout.md'
1313
- status: 'cmd/status.md'
14-
- accesstoken get: 'cmd/accesstoken-get.md'
1514
- Azure Active Directory Graph (aad):
1615
- approleassignment:
1716
- approleassignment list: 'cmd/aad/approleassignment/approleassignment-list.md'
@@ -438,6 +437,9 @@ nav:
438437
- user:
439438
- user get: 'cmd/yammer/user/user-get.md'
440439
- user list: 'cmd/yammer/user/user-list.md'
440+
- Utilities (util):
441+
- accesstoken:
442+
- accesstoken get: 'cmd/util/accesstoken/accesstoken-get.md'
441443
- Concepts:
442444
- 'Persisting connection': 'concepts/persisting-connection.md'
443445
- 'Authorization and access tokens': 'concepts/authorization-tokens.md'

src/o365/util/commands.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
const prefix: string = 'util';
2+
3+
export default {
4+
UTIL_ACCESSTOKEN_GET: `${prefix} accesstoken get`
5+
};

src/o365/commands/accesstoken-get.spec.ts renamed to src/o365/util/commands/accesstoken/accesstoken-get.spec.ts

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
1-
import commands from './commands';
2-
import Command, { CommandOption, CommandValidate, CommandError } from '../../Command';
1+
import commands from '../../commands';
2+
import globalCommands from '../../../commands/commands';
3+
import Command, { CommandOption, CommandValidate, CommandError } from '../../../../Command';
34
import * as sinon from 'sinon';
45
const command: Command = require('./accesstoken-get');
56
import * as assert from 'assert';
6-
import Utils from '../../Utils';
7-
import appInsights from '../../appInsights';
8-
import auth from '../../Auth';
7+
import Utils from '../../../../Utils';
8+
import appInsights from '../../../../appInsights';
9+
import auth from '../../../../Auth';
910

10-
describe(commands.ACCESSTOKEN_GET, () => {
11+
describe(commands.UTIL_ACCESSTOKEN_GET, () => {
1112
let vorpal: Vorpal;
1213
let log: any[];
1314
let cmdInstanceLogSpy: sinon.SinonSpy;
@@ -20,7 +21,7 @@ describe(commands.ACCESSTOKEN_GET, () => {
2021
});
2122

2223
beforeEach(() => {
23-
vorpal = require('../../vorpal-init');
24+
vorpal = require('../../../../vorpal-init');
2425
log = [];
2526
cmdInstance = {
2627
commandWrapper: {
@@ -50,13 +51,23 @@ describe(commands.ACCESSTOKEN_GET, () => {
5051
});
5152

5253
it('has correct name', () => {
53-
assert.equal(command.name.startsWith(commands.ACCESSTOKEN_GET), true);
54+
assert.equal(command.name.startsWith(commands.UTIL_ACCESSTOKEN_GET), true);
5455
});
5556

5657
it('has a description', () => {
5758
assert.notEqual(command.description, null);
5859
});
5960

61+
it('defines alias', () => {
62+
const alias = command.alias();
63+
assert.notEqual(typeof alias, 'undefined');
64+
});
65+
66+
it('defines correct alias', () => {
67+
const alias = command.alias();
68+
assert.equal((alias && alias.indexOf(globalCommands.ACCESSTOKEN_GET) > -1), true);
69+
});
70+
6071
it('retrieves access token for the specified resource', (done) => {
6172
const d: Date = new Date();
6273
d.setMinutes(d.getMinutes() + 1);
@@ -130,7 +141,7 @@ describe(commands.ACCESSTOKEN_GET, () => {
130141
const find = sinon.stub(vorpal, 'find').callsFake(() => cmd);
131142
cmd.help = command.help();
132143
cmd.help({}, () => { });
133-
assert(find.calledWith(commands.ACCESSTOKEN_GET));
144+
assert(find.calledWith(commands.UTIL_ACCESSTOKEN_GET));
134145
});
135146

136147
it('has help with examples', () => {

src/o365/commands/accesstoken-get.ts renamed to src/o365/util/commands/accesstoken/accesstoken-get.ts

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
1-
import commands from './commands';
2-
import GlobalOptions from '../../GlobalOptions';
1+
import commands from '../../commands';
2+
import globalCommands from '../../../commands/commands';
3+
import GlobalOptions from '../../../../GlobalOptions';
34
import Command, {
45
CommandOption,
56
CommandValidate,
67
CommandError
7-
} from '../../Command';
8-
import auth from '../../Auth';
8+
} from '../../../../Command';
9+
import auth from '../../../../Auth';
910

10-
const vorpal: Vorpal = require('../../vorpal-init');
11+
const vorpal: Vorpal = require('../../../../vorpal-init');
1112

1213
interface CommandArgs {
1314
options: Options;
@@ -20,14 +21,20 @@ interface Options extends GlobalOptions {
2021

2122
class AccessTokenGetCommand extends Command {
2223
public get name(): string {
23-
return `${commands.ACCESSTOKEN_GET}`;
24+
return `${commands.UTIL_ACCESSTOKEN_GET}`;
2425
}
2526

2627
public get description(): string {
2728
return 'Gets access token for the specified resource';
2829
}
2930

31+
public alias(): string[] | undefined {
32+
return [globalCommands.ACCESSTOKEN_GET];
33+
}
34+
3035
public commandAction(cmd: CommandInstance, args: CommandArgs, cb: (err?: any) => void): void {
36+
this.showDeprecationWarning(cmd, globalCommands.ACCESSTOKEN_GET, commands.UTIL_ACCESSTOKEN_GET);
37+
3138
auth
3239
.ensureAccessToken(args.options.resource, cmd, this.debug, args.options.new)
3340
.then((accessToken: string): void => {

0 commit comments

Comments
 (0)