Class TokenHelper
Methods for working with auth tokens and creating authorized client contexts
Inheritance
Inherited Members
Namespace:AzureFunctionsForSharePoint.Common
Assembly:AzureFunctionsForSharePoint.Common.dll
Syntax
public class TokenHelper
Methods
| Improve this Doc View SourceBase64DecodeJwtToken(String)
Declaration
public static string Base64DecodeJwtToken(string arg)
Parameters
Type | Name | Description |
---|---|---|
System.String | arg |
Returns
Type | Description |
---|---|
System.String |
Base64UrlEncode(String)
Declaration
public static string Base64UrlEncode(string input)
Parameters
Type | Name | Description |
---|---|---|
System.String | input |
Returns
Type | Description |
---|---|
System.String |
GetACSAccessTokens(SharePointContextToken, String, String, String)
Retrieves an access token from ACS to call the source of the specified context token at the specified targetHost. The targetHost must be registered for principal the that sent the context token.
Declaration
public static OAuth2AccessTokenResponse GetACSAccessTokens(SharePointContextToken contextToken, string targetHost, string clientId, string clientSecret)
Parameters
Type | Name | Description |
---|---|---|
SharePointContextToken | contextToken | Context token issued by the intended access token audience |
System.String | targetHost | Url authority of the target principal |
System.String | clientId | ACS client id |
System.String | clientSecret | ACS client secret |
Returns
Type | Description |
---|---|
Microsoft.IdentityModel.S2S.Protocols.OAuth2.OAuth2AccessTokenResponse | An access token with an audience matching the context token's source |
GetACSAccessTokens(String, String, String, String, String, String)
Uses the specified refresh token to retrieve an access token from ACS to call the specified principal at the specified targetHost. The targetHost must be registered for target principal. If specified realm is null, the "Realm" setting in web.config will be used instead.
Declaration
public static OAuth2AccessTokenResponse GetACSAccessTokens(string refreshToken, string targetPrincipalName, string targetHost, string targetRealm, string clientId, string clientSecret)
Parameters
Type | Name | Description |
---|---|---|
System.String | refreshToken | Refresh token to exchange for access token |
System.String | targetPrincipalName | Name of the target principal to retrieve an access token for |
System.String | targetHost | Url authority of the target principal |
System.String | targetRealm | Realm to use for the access token's nameid and audience |
System.String | clientId | ACS client id |
System.String | clientSecret | Client secret |
Returns
Type | Description |
---|---|
Microsoft.IdentityModel.S2S.Protocols.OAuth2.OAuth2AccessTokenResponse | An access token with an audience of the target principal |
GetAppOnlyAccessToken(String, String, String, String, String)
Retrieves an app-only access token from ACS to call the specified principal at the specified targetHost. The targetHost must be registered for target principal. If specified realm is null, the "Realm" setting in web.config will be used instead.
Declaration
public static OAuth2AccessTokenResponse GetAppOnlyAccessToken(string targetPrincipalName, string targetHost, string targetRealm, string clientId, string clientSecret)
Parameters
Type | Name | Description |
---|---|---|
System.String | targetPrincipalName | Name of the target principal to retrieve an access token for |
System.String | targetHost | Url authority of the target principal |
System.String | targetRealm | Realm to use for the access token's nameid and audience |
System.String | clientId | ACS client id |
System.String | clientSecret | ACS client secret |
Returns
Type | Description |
---|---|
Microsoft.IdentityModel.S2S.Protocols.OAuth2.OAuth2AccessTokenResponse | An access token with an audience of the target principal |
GetClientContext(String, String)
Uses the specified access token to create a client context
Declaration
public static ClientContext GetClientContext(string targetUrl, string accessToken)
Parameters
Type | Name | Description |
---|---|---|
System.String | targetUrl | Url of the target SharePoint site |
System.String | accessToken | Access token to be used when calling the specified targetUrl |
Returns
Type | Description |
---|---|
Microsoft.SharePoint.Client.ClientContext | A ClientContext ready to call targetUrl with the specified access token |
ReadAndValidateContextToken(String, String, String, String)
Reads and validates a contextTokenString sent from SharePoint as the result of app launch or a remote event
Declaration
public static SharePointContextToken ReadAndValidateContextToken(string contextTokenString, string appHostName, string clientId, string clientSecret)
Parameters
Type | Name | Description |
---|---|---|
System.String | contextTokenString | The string sent by SharePoint |
System.String | appHostName | The app host (host part of the site URL) |
System.String | clientId | A valid client id |
System.String | clientSecret | A valid client secret |
Returns
Type | Description |
---|---|
SharePointContextToken |