<commit_before>
# Creating a ServicePrincipal for scripting scenarios
One does not want to login interactively all the time. Azure provides service principal authentication as a secure way for silent login.

## Via Portal
[This article](https://azure.microsoft.com/en-us/documentation/articles/resource-group-create-service-principal-portal/) provides detailed steps on creating a service principal via portal.

## Via XplatCLI
Pre-requisite:
- Install the latest version of cli from the [latest github release](https://github.com/Azure/azure-xplat-cli/releases) or from [npm](https://npmjs.com/package/azure-cli).

```bash
npm uninstall azure-cli -g
npm cache clear -g
npm install azure-cli -g
```
- Login to the azure-cli via azure login command to create a service principal for future use.
  - For 2FA enabled user accounts  `azure login`
  - For non 2FA enabled user accounts `azure login -u <EMAIL>`

After successful login, please follow the steps mentioned below to create a serviceprincipal:
#### Step 0: Please make sure you have selected the correct subscription. The service principal will have access to your current subscription.
- To list all your subscriptions: `azure account list`
- To set the subscription of your choice: `azure account set "your subscription name"`

#### Step 1. Create an aplication

Let us create an application with a password. The default start-date witll be the day of application creation and the default end-date will be 1 year from the day of creation.

> ###### NOTE: The AppId that gets created in this command is also known as clientId. It is the id given by ADAL for itself to identify your application. You can use this as the clientId during user authentication (creating UserTokenCredentials object).

```
D:\sdk>azure ad app create -n testap908 --home-page http://www.bing.com --identifier-uris https://testap674.com/home -p P@ssw0rd
info:    Executing command ad app create
+ Creating application testap674
data:    AppId:                   56894bd4-0fde-41d8-a0d7-5bsslccety2   //<<<<<<<< Also known as clientId.
data:    ObjectId:                g565675e8-7c30-908t-8548-87r98ew7rej
data:    DisplayName:             testap674
data:    IdentifierUris:          0=https://testap674.com/home
data:    ReplyUrls:
data:    AvailableToOtherTenants:  False
data:    AppPermissions:
data:                             claimValue:  user_impersonation
data:                             description:  Allow the application to access testap674 on behalf of the signed-in user.
data:                             directAccessGrantTypes:
data:                             displayName:  Access testap674
data:                             impersonationAccessGrantTypes:  impersonated=User, impersonator=Application
data:                             isDisabled:<commit_msg>Update Authentication.md<commit_after>
# Creating a ServicePrincipal for scripting scenarios
One does not want to login interactively all the time. Azure provides service principal authentication as a secure way for silent login.

## Via Portal
[This article](https://azure.microsoft.com/en-us/documentation/articles/resource-group-create-service-principal-portal/) provides detailed steps on creating a service principal via portal.

## Via XplatCLI
Pre-requisite:
- Install the latest version of cli from the [latest github release](https://github.com/Azure/azure-xplat-cli/releases) or from [npm](https://npmjs.com/package/azure-cli).

```bash
npm uninstall azure-cli -g
npm cache clear -g
npm install azure-cli -g
```
- Login to the azure-cli via azure login command to create a service principal for future use.
  - For 2FA enabled user accounts  `azure login`
  - For non 2FA enabled user accounts `azure login -u <EMAIL>`

After successful login, please follow the steps mentioned below to create a serviceprincipal:
#### Step 0. Please make sure you have selected the correct subscription. The service principal will have access to your current subscription.
- To list all your subscriptions: `azure account list`
- To set the subscription of your choice: `azure account set "your subscription name"`

#### Step 1. Create an aplication

Let us create an application with a password. The default start-date witll be the day of application creation and the default end-date will be 1 year from the day of creation.

> ###### NOTE: The AppId that gets created in this command is also known as clientId. It is the id given by ADAL for itself to identify your application. You can use this as the clientId during user authentication (creating UserTokenCredentials object).

```
D:\sdk>azure ad app create -n testap908 --home-page http://www.bing.com --identifier-uris https://testap674.com/home -p P@ssw0rd
info:    Executing command ad app create
+ Creating application testap674
data:    AppId:                   56894bd4-0fde-41d8-a0d7-5bsslccety2   //<<<<<<<< Also known as clientId.
data:    ObjectId:                g565675e8-7c30-908t-8548-87r98ew7rej
data:    DisplayName:             testap674
data:    IdentifierUris:          0=https://testap674.com/home
data:    ReplyUrls:
data:    AvailableToOtherTenants:  False
data:    AppPermissions:
data:                             claimValue:  user_impersonation
data:                             description:  Allow the application to access testap674 on behalf of the signed-in user.
data:                             directAccessGrantTypes:
data:                             displayName:  Access testap674
data:                             impersonationAccessGrantTypes:  impersonated=User, impersonator=Application
data:                             isDisabled:
{'fraction_non_alphanumeric': 0.07331794780756258, 'fraction_numerical': 0.02272323806142375, 'mean_word_length': 3.1064139941690962, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 9, 'https://': 10, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5913581', 'n_tokens_mistral': 1579, 'n_tokens_neox': 1464, 'n_words': 620}