Skip to content

Commit

Permalink
added RO flow and client
Browse files Browse the repository at this point in the history
  • Loading branch information
TahirNaushad committed Jul 26, 2017
1 parent b16ea07 commit 603ea3c
Show file tree
Hide file tree
Showing 4 changed files with 88 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp1.1</TargetFramework>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="IdentityModel" Version="2.10.0" />
</ItemGroup>

</Project>
54 changes: 54 additions & 0 deletions Fiver.Security.AuthServer.Client.RO/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
using IdentityModel.Client;
using Newtonsoft.Json.Linq;
using System;
using System.Net.Http;

namespace Fiver.Security.AuthServer.Client.RO
{
class Program
{
static void Main(string[] args)
{
try
{
// discover endpoints from metadata
var disco = DiscoveryClient.GetAsync("http://localhost:5000").Result;

// request token
var tokenClient = new TokenClient(disco.TokenEndpoint, "fiver_auth_client_ro", "secret");
var tokenResponse = tokenClient.RequestResourceOwnerPasswordAsync("james", "password", "fiver_auth_api").Result;

if (tokenResponse.IsError)
{
Console.WriteLine(tokenResponse.Error);
return;
}

//Console.WriteLine(tokenResponse.Json);

// call api
var client = new HttpClient();
client.SetBearerToken(tokenResponse.AccessToken);

var response = client.GetAsync("http://localhost:5001/movies").Result;
if (!response.IsSuccessStatusCode)
{
Console.WriteLine(response.StatusCode);
}
else
{
var content = response.Content.ReadAsStringAsync().Result;
Console.WriteLine(JArray.Parse(content));
}
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
finally
{
Console.ReadLine();
}
}
}
}
10 changes: 8 additions & 2 deletions Fiver.Security.AuthServer.sln
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@ VisualStudioVersion = 15.0.26430.12
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Fiver.Security.AuthServer", "Fiver.Security.AuthServer\Fiver.Security.AuthServer.csproj", "{528E675A-7076-4ADF-BC41-1F3765BC52D6}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Fiver.Security.AuthServer.Api", "Fiver.Security.AuthServer.Api\Fiver.Security.AuthServer.Api.csproj", "{C3BEE935-B3F0-45B4-8301-38A5626D444D}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Fiver.Security.AuthServer.Api", "Fiver.Security.AuthServer.Api\Fiver.Security.AuthServer.Api.csproj", "{C3BEE935-B3F0-45B4-8301-38A5626D444D}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Fiver.Security.AuthServer.Client", "Fiver.Security.AuthServer.Client\Fiver.Security.AuthServer.Client.csproj", "{9713B175-B5FC-48B5-B896-64BACDE27D22}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Fiver.Security.AuthServer.Client", "Fiver.Security.AuthServer.Client\Fiver.Security.AuthServer.Client.csproj", "{9713B175-B5FC-48B5-B896-64BACDE27D22}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Fiver.Security.AuthServer.Client.RO", "Fiver.Security.AuthServer.Client.RO\Fiver.Security.AuthServer.Client.RO.csproj", "{93040B5E-7EF4-4CC7-BC4F-F98929B6AF66}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand All @@ -27,6 +29,10 @@ Global
{9713B175-B5FC-48B5-B896-64BACDE27D22}.Debug|Any CPU.Build.0 = Debug|Any CPU
{9713B175-B5FC-48B5-B896-64BACDE27D22}.Release|Any CPU.ActiveCfg = Release|Any CPU
{9713B175-B5FC-48B5-B896-64BACDE27D22}.Release|Any CPU.Build.0 = Release|Any CPU
{93040B5E-7EF4-4CC7-BC4F-F98929B6AF66}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{93040B5E-7EF4-4CC7-BC4F-F98929B6AF66}.Debug|Any CPU.Build.0 = Debug|Any CPU
{93040B5E-7EF4-4CC7-BC4F-F98929B6AF66}.Release|Any CPU.ActiveCfg = Release|Any CPU
{93040B5E-7EF4-4CC7-BC4F-F98929B6AF66}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
14 changes: 14 additions & 0 deletions Fiver.Security.AuthServer/Config.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,20 @@ public static IEnumerable<Client> GetClients()
IdentityServerConstants.StandardScopes.Profile,
"fiver_auth_api"
},
},
// Resource Owner Password Flow
new Client
{
ClientId = "fiver_auth_client_ro",
ClientName = "Fiver.Security.AuthServer.Client.RO",
ClientSecrets = { new Secret("secret".Sha256()) },

AllowedGrantTypes = GrantTypes.ResourceOwnerPassword,

AllowedScopes =
{
"fiver_auth_api"
},
}
};
}
Expand Down

0 comments on commit 603ea3c

Please sign in to comment.