public static async Task <Credentials> GetCredentialsAsync(BotOptions options) { if (!String.IsNullOrEmpty(options.AppKey)) { return(await GetCredentialsForAppAsync(options)); } else if (!String.IsNullOrEmpty(options.AccessToken)) { return(GetCredentialsForUser(options)); } else { return(await GetCredentialsFromStore()); } }
public static async Task <Credentials> GetCredentialsForAppAsync(BotOptions options) { var creds = new SigningCredentials(GetRsaSecurityKeyFromPemKey(options.AppKey), SecurityAlgorithms.RsaSha256); var jwtToken = new JwtSecurityToken( new JwtHeader(creds), new JwtPayload( issuer: options.AppId, issuedAt: DateTime.Now, expires: DateTime.Now.Add(GitHubJwtTimeout), audience: null, claims: null, notBefore: null)); var jwtTokenString = new JwtSecurityTokenHandler().WriteToken(jwtToken); var initClient = new GitHubClient(ClientHeader) { Credentials = new Credentials(jwtTokenString, AuthenticationType.Bearer), }; var installationToken = await initClient.GitHubApps.CreateInstallationToken(options.InstallId); return(new Credentials(installationToken.Token, AuthenticationType.Bearer)); }
public static Credentials GetCredentialsForUser(BotOptions options) { return(new Credentials(options.AccessToken)); }