Skip to content

Commit b2f3dcc

Browse files
authored
Improvements for Moodle Provider (#533)
* Add Claims for auth, country and description * Fixed wrong code style * Moved doc references from [projectestac/moodle-local_oauth] to [HIT-ReFreSH/moodle-local_oauth] * Added Tests for new Claims
1 parent d37d0d3 commit b2f3dcc

File tree

6 files changed

+24
-8
lines changed

6 files changed

+24
-8
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ If a provider you're looking for does not exist, consider making a PR to add one
150150
| LinkedIn | [![NuGet](https://buildstats.info/nuget/AspNet.Security.OAuth.LinkedIn?includePreReleases=false)](https://www.nuget.org/packages/AspNet.Security.OAuth.LinkedIn/ "Download AspNet.Security.OAuth.LinkedIn from NuGet.org") | [![MyGet](https://buildstats.info/myget/aspnet-contrib/AspNet.Security.OAuth.LinkedIn?includePreReleases=true)](https://www.myget.org/feed/aspnet-contrib/package/nuget/AspNet.Security.OAuth.LinkedIn "Download AspNet.Security.OAuth.LinkedIn from MyGet.org") | [Documentation](https://docs.microsoft.com/en-us/linkedin/shared/authentication/authentication "LinkedIn developer documentation") |
151151
| MailChimp | [![NuGet](https://buildstats.info/nuget/AspNet.Security.OAuth.MailChimp?includePreReleases=false)](https://www.nuget.org/packages/AspNet.Security.OAuth.MailChimp/ "Download AspNet.Security.OAuth.MailChimp from NuGet.org") | [![MyGet](https://buildstats.info/myget/aspnet-contrib/AspNet.Security.OAuth.MailChimp?includePreReleases=true)](https://www.myget.org/feed/aspnet-contrib/package/nuget/AspNet.Security.OAuth.MailChimp "Download AspNet.Security.OAuth.MailChimp from MyGet.org") | [Documentation](https://developer.mailchimp.com/documentation/mailchimp/guides/how-to-use-oauth2/ "MailChimp developer documentation") |
152152
| MailRu | [![NuGet](https://buildstats.info/nuget/AspNet.Security.OAuth.MailRu?includePreReleases=false)](https://www.nuget.org/packages/AspNet.Security.OAuth.MailRu/ "Download AspNet.Security.OAuth.MailRu from NuGet.org") | [![MyGet](https://buildstats.info/myget/aspnet-contrib/AspNet.Security.OAuth.MailRu?includePreReleases=true)](https://www.myget.org/feed/aspnet-contrib/package/nuget/AspNet.Security.OAuth.MailRu "Download AspNet.Security.OAuth.MailRu from MyGet.org") | [Documentation](https://o2.mail.ru/docs#web "MailRu developer documentation") |
153-
| Moodle | [![NuGet](https://buildstats.info/nuget/AspNet.Security.OAuth.Moodle?includePreReleases=false)](https://www.nuget.org/packages/AspNet.Security.OAuth.Moodle/ "Download AspNet.Security.OAuth.Moodle from NuGet.org") | [![MyGet](https://buildstats.info/myget/aspnet-contrib/AspNet.Security.OAuth.Moodle?includePreReleases=true)](https://www.myget.org/feed/aspnet-contrib/package/nuget/AspNet.Security.OAuth.Moodle "Download AspNet.Security.OAuth.Moodle from MyGet.org") | [Documentation](https://github.com/projectestac/moodle-local_oauth "Moodle OAuth2 plugin developer documentation") |
153+
| Moodle | [![NuGet](https://buildstats.info/nuget/AspNet.Security.OAuth.Moodle?includePreReleases=false)](https://www.nuget.org/packages/AspNet.Security.OAuth.Moodle/ "Download AspNet.Security.OAuth.Moodle from NuGet.org") | [![MyGet](https://buildstats.info/myget/aspnet-contrib/AspNet.Security.OAuth.Moodle?includePreReleases=true)](https://www.myget.org/feed/aspnet-contrib/package/nuget/AspNet.Security.OAuth.Moodle "Download AspNet.Security.OAuth.Moodle from MyGet.org") | [Documentation](https://github.com/HIT-ReFreSH/moodle-local_oauth "Moodle OAuth2 plugin developer documentation") |
154154
| Myob | [![NuGet](https://buildstats.info/nuget/AspNet.Security.OAuth.Myob?includePreReleases=false)](https://www.nuget.org/packages/AspNet.Security.OAuth.Myob/ "Download AspNet.Security.OAuth.Myob from NuGet.org") | [![MyGet](https://buildstats.info/myget/aspnet-contrib/AspNet.Security.OAuth.Myob?includePreReleases=true)](https://www.myget.org/feed/aspnet-contrib/package/nuget/AspNet.Security.OAuth.Myob "Download AspNet.Security.OAuth.Myob from MyGet.org") | [Documentation](https://developer.myob.com/api/accountright/api-overview/authentication/ "Myob developer documentation") |
155155
| NetEase | [![NuGet](https://buildstats.info/nuget/AspNet.Security.OAuth.NetEase?includePreReleases=false)](https://www.nuget.org/packages/AspNet.Security.OAuth.NetEase/ "Download AspNet.Security.OAuth.NetEase from NuGet.org") | [![MyGet](https://buildstats.info/myget/aspnet-contrib/AspNet.Security.OAuth.NetEase?includePreReleases=true)](https://www.myget.org/feed/aspnet-contrib/package/nuget/AspNet.Security.OAuth.NetEase "Download AspNet.Security.OAuth.NetEase from MyGet.org") | [Documentation](https://reg.163.com/help/help_oauth2.html "NetEase developer documentation") |
156156
| Nextcloud | [![NuGet](https://buildstats.info/nuget/AspNet.Security.OAuth.Nextcloud?includePreReleases=false)](https://www.nuget.org/packages/AspNet.Security.OAuth.Nextcloud/ "Download AspNet.Security.OAuth.Nextcloud from NuGet.org") | [![MyGet](https://buildstats.info/myget/aspnet-contrib/AspNet.Security.OAuth.Nextcloud?includePreReleases=true)](https://www.myget.org/feed/aspnet-contrib/package/nuget/AspNet.Security.OAuth.Nextcloud "Download AspNet.Security.OAuth.Nextcloud from MyGet.org") | [Documentation](https://docs.nextcloud.com/server/14/admin_manual/configuration_server/oauth2.html "Nextcloud developer documentation") [User EndPoint Documentation](https://docs.nextcloud.com/server/15/developer_manual/client_apis/OCS/index.html#user-metadata "Nextcloud developer documentation") |

docs/moodle.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Integrating the Moodle Provider
22

3-
Applies to the Moodle plugin [projectestac/moodle-local_oauth](https://github.com/projectestac/moodle-local_oauth).
3+
Applies to the Moodle plugin [HIT-ReFreSH/moodle-local_oauth](https://github.com/HIT-ReFreSH/moodle-local_oauth).
44

55
## Example
66

src/AspNet.Security.OAuth.Moodle/MoodleAuthenticationConstants.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ public static class Claims
1616
public const string IdNumber = "urn:moodle:idnumber";
1717
public const string MoodleId = "urn:moodle:id";
1818
public const string Language = "urn:moodle:lang";
19+
public const string Description = "urn:moodle:desc";
1920
}
2021
}
2122
}

src/AspNet.Security.OAuth.Moodle/MoodleAuthenticationOptions.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,12 @@ public MoodleAuthenticationOptions()
3737
ClaimActions.MapJsonKey(ClaimTypes.MobilePhone, "phone1");
3838
ClaimActions.MapJsonKey(ClaimTypes.GivenName, "firstname");
3939
ClaimActions.MapJsonKey(ClaimTypes.Surname, "lastname");
40+
ClaimActions.MapJsonKey(ClaimTypes.AuthenticationMethod, "auth");
41+
ClaimActions.MapJsonKey(ClaimTypes.Country, "country");
4042
ClaimActions.MapJsonKey(Claims.IdNumber, "idnumber");
4143
ClaimActions.MapJsonKey(Claims.MoodleId, "id");
4244
ClaimActions.MapJsonKey(Claims.Language, "lang");
45+
ClaimActions.MapJsonKey(Claims.Description, "description");
4346
}
4447

4548
/// <summary>

test/AspNet.Security.OAuth.Providers.Tests/Moodle/MoodleTests.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,12 @@ protected internal override void RegisterAuthentication(AuthenticationBuilder bu
3939
[InlineData(ClaimTypes.Surname, "Doe")]
4040
[InlineData(ClaimTypes.GivenName, "John")]
4141
[InlineData(ClaimTypes.MobilePhone, "7654321")]
42+
[InlineData(ClaimTypes.Country, "avalon")]
43+
[InlineData(ClaimTypes.AuthenticationMethod, "manual")]
4244
[InlineData(Claims.IdNumber, "1234567")]
4345
[InlineData(Claims.MoodleId, "22")]
4446
[InlineData(Claims.Language, "en")]
47+
[InlineData(Claims.Description, "John Doe's Moodle account")]
4548
public async Task Can_Sign_In_Using_Moodle(string claimType, string claimValue)
4649
{
4750
// Arrange
@@ -64,6 +67,9 @@ public async Task Can_Sign_In_Using_Moodle(string claimType, string claimValue)
6467
[InlineData(Claims.IdNumber, "ZH1234567")]
6568
[InlineData(Claims.MoodleId, "22")]
6669
[InlineData(Claims.Language, "zh_CN")]
70+
[InlineData(ClaimTypes.Country, "秦")]
71+
[InlineData(ClaimTypes.AuthenticationMethod, "casattras")]
72+
[InlineData(Claims.Description, "张三的 Moodle 账号")]
6773
public async Task Can_Sign_In_Using_Moodle_In_Chinese(string claimType, string claimValue)
6874
{
6975
// Arrange

test/AspNet.Security.OAuth.Providers.Tests/Moodle/bundle.json

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"$schema": "https://raw.githubusercontent.com/justeat/httpclient-interception/master/src/HttpClientInterception/Bundles/http-request-bundle-schema.json",
33
"items": [
44
{
5-
"comment": "https://github.com/projectestac/moodle-local_oauth",
5+
"comment": "https://github.com/HIT-ReFreSH/moodle-local_oauth",
66
"uri": "https://moodle.local/local/oauth/token.php",
77
"method": "POST",
88
"contentFormat": "json",
@@ -15,7 +15,7 @@
1515
}
1616
},
1717
{
18-
"comment": "https://github.com/projectestac/moodle-local_oauth",
18+
"comment": "https://github.com/HIT-ReFreSH/moodle-local_oauth",
1919
"uri": "https://moodle.local/local/oauth/user_info.php",
2020
"contentFormat": "json",
2121
"contentJson": {
@@ -26,11 +26,14 @@
2626
"lastname": "Doe",
2727
"email": "[email protected]",
2828
"lang": "en",
29-
"phone1": "7654321"
29+
"phone1": "7654321",
30+
"auth": "manual",
31+
"country": "avalon",
32+
"description": "John Doe's Moodle account"
3033
}
3134
},
3235
{
33-
"comment": "https://github.com/projectestac/moodle-local_oauth",
36+
"comment": "https://github.com/HIT-ReFreSH/moodle-local_oauth",
3437
"uri": "https://zh.moodle.local/local/oauth/token.php",
3538
"method": "POST",
3639
"contentFormat": "json",
@@ -43,7 +46,7 @@
4346
}
4447
},
4548
{
46-
"comment": "https://github.com/projectestac/moodle-local_oauth",
49+
"comment": "https://github.com/HIT-ReFreSH/moodle-local_oauth",
4750
"uri": "https://zh.moodle.local/local/oauth/user_info.php",
4851
"contentFormat": "json",
4952
"contentJson": {
@@ -54,7 +57,10 @@
5457
"lastname": "",
5558
"email": "[email protected]",
5659
"lang": "zh_CN",
57-
"phone1": "7654321"
60+
"phone1": "7654321",
61+
"auth": "casattras",
62+
"country": "",
63+
"description": "张三的 Moodle 账号"
5864
}
5965
}
6066
]

0 commit comments

Comments
 (0)